大佬教程收集整理的这篇文章主要介绍了一步一步学Silverlight 2系列(17):数据与通信之ADO.NET Data Services,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public class Post { public int Id { get; set; } public String title { get; set; } public String Author { get; set; } }
public class Post { [DataWebKey] public int Id { get; set; } public String title { get; set; } public String Author { get; set; } }
public class Blog { public Blog() { _post.Add(new Post { Id = 1,title = "一步一步学Silverlight 2系列(13):数据与通信之Webrequest",Author = "TerryLee" }); _post.Add(new Post { Id = 2,title = "一步一步学Silverlight 2系列(12):数据与通信之WebClient",Author = "TerryLee" }); _post.Add(new Post { Id = 3,title = "一步一步学Silverlight 2系列(11):数据绑定",Author = "TerryLee" }); _post.Add(new Post { Id = 4,title = "一步一步学Silverlight 2系列(10):使用用户控件",Author = "TerryLee" }); _post.Add(new Post { Id = 5,title = "一步一步学Silverlight 2系列(9):使用控件模板",Author = "TerryLee" }); _post.Add(new Post { Id = 6,title = "一步一步学Silverlight 2系列(8):使用样式封装控件观感",Author = "TerryLee" }); } List<Post> _post = new List<Post>(); public IQueryable<Post> Posts { get { return _post.AsQueryable<Post>(); } } }
public class BlogDataservice : WebDataservice<Blog> { public static void Initializeservice(IWebDataserviceConfiguration config) { config.SetresourceContainerAccessRule("*",resourceContainerRights.AllRead); } }
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <Feed xml:base="[url]http://localhost:8081/BlogDataservice.svc/[/url]" ......> <id>[url]http://localhost:8081/BlogDataservice.svc/Posts[/url]</id> <updated /> <title>Posts</title> <link rel="self" href="Posts" title="Posts" /> <entry adsm:type="TerryLee.SilverlightWithDataserviceDemoWeb.Post"> <id>[url]http://localhost:8081/BlogDataservice.svc/Posts[/url](1)</id> <updated /> <title /> <author> <name /> </author> <link rel="edit" href="Posts(1)" title="Post" /> <content type="application/xml"> <ads:Id adsm:type="Int32">1</ads:Id> <ads@R_130_6964@>一步一步学Silverlight 2系列(13):数据与通信之Webrequest</ads@R_130_6964@> <ads:Author>TerryLee</ads:Author> </content> </entry>
@H_552_404@
private void UserControl_Loaded(object sender,RoutedEventArgs E) { Uri uri = new Uri("http://localhost:8081/BlogDataservice.svc/Posts"); WebClient client = new WebClient(); client.openReadCoR_929_11845@pleted += new OpenReadCoR_929_11845@pletedEventHandler(client_OpenReadCoR_929_11845@pleted); client.openReadAsync(uri); } void client_OpenReadCoR_929_11845@pleted(object sender,OpenReadCoR_929_11845@pletedEventArgs E) { if (e.Error == null) { } }
XmlReader reader = XmlReader.Create(e.Result); XDocument postdoc = XDocument.Load(reader); XNamespace xmlns = "http://www.w3.org/2005/Atom"; XNamespace ads = "http://scheR_929_11845@as.microsoft.com/ado/2007/08/dataweb"; var posts = from x in postdoc.Descendants(xmlns + "entry") SELEct new Post { Id = int.Parse(x.Descendants(ads + "Id").First().value),title = x.Descendants(ads + "title").First().Value,Author = x.Descendants(ads + "Author").First().Value }; Posts.Itemssource = posts;
private void UserControl_Loaded(object sender,OpenReadCoR_929_11845@pletedEventArgs E) { if (e.Error == null) { XmlReader reader = XmlReader.Create(e.Result); XDocument postdoc = XDocument.Load(reader); XNamespace xmlns = "http://www.w3.org/2005/Atom"; XNamespace ads = "http://scheR_929_11845@as.microsoft.com/ado/2007/08/dataweb"; var posts = from x in postdoc.Descendants(xmlns + "entry") SELEct new Post { Id = int.Parse(x.Descendants(ads + "Id").First().value),Author = x.Descendants(ads + "Author").First().Value }; Posts.Itemssource = posts; } }
以上是大佬教程为你收集整理的一步一步学Silverlight 2系列(17):数据与通信之ADO.NET Data Services全部内容,希望文章能够帮你解决一步一步学Silverlight 2系列(17):数据与通信之ADO.NET Data Services所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。