2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
2009-06-08 22:01
756 查看
介绍
Silverlight 2.0 调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
通过 System.Net.WebClient 类调用 REST 服务
通过 System.Json 命名控件下的类处理 JSON 数据
通过 System.Xml.Linq 命名空间下的类(LINQ to XML)处理 XML 数据
通过 System.ServiceModel.Syndication 命名空间下的类处理 RSS/ATOM 数据
在线DEMO
/article/4589581.html
示例
1、调用 REST 服务,返回 JSON 数据
REST.cs(WCF创建的REST服务)
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Collections.Generic;
using System.Text;
using System.IO;
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class REST
Json.xaml
<UserControl x:Class="Silverlight20.Communication.Json"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Width="600">
<TextBox x:Name="txtMsgJson" Margin="5" />
<TextBox x:Name="txtMsgJson2" Margin="5" />
</StackPanel>
</UserControl>
Json.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
namespace Silverlight20.Communication
2、调用 REST 服务,返回 XML 数据
REST.cs(WCF创建的REST服务)
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Collections.Generic;
using System.Text;
using System.IO;
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class REST
Xml.xaml
<UserControl x:Class="Silverlight20.Communication.Xml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Width="600">
<TextBox x:Name="txtMsgXml" Margin="5" />
<TextBox x:Name="txtMsgXml2" Margin="5" />
</StackPanel>
</UserControl>
Xml.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.IO;
namespace Silverlight20.Communication
3、调用 REST 服务,返回 Rss/Atom 数据
Proxy.aspx.cs(返回指定的url地址的内容的服务)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Proxy : System.Web.UI.Page
RssAtom.xaml
<UserControl x:Class="Silverlight20.Communication.RssAtom"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" >
<TextBox x:Name="txtMsgRss" Width="600" Margin="5" />
<StackPanel Orientation="Horizontal">
<ListBox x:Name="list" Width="300" Margin="5" SelectionChanged="list_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title.Text}"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock x:Name="detail" Width="300" Margin="5" Text="{Binding Summary.Text}" TextWrapping="Wrap" />
</StackPanel>
</StackPanel>
</UserControl>
RssAtom.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using System.IO;
using System.ServiceModel.Syndication;
namespace Silverlight20.Communication
Silverlight 2.0 调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
通过 System.Net.WebClient 类调用 REST 服务
通过 System.Json 命名控件下的类处理 JSON 数据
通过 System.Xml.Linq 命名空间下的类(LINQ to XML)处理 XML 数据
通过 System.ServiceModel.Syndication 命名空间下的类处理 RSS/ATOM 数据
在线DEMO
/article/4589581.html
示例
1、调用 REST 服务,返回 JSON 数据
REST.cs(WCF创建的REST服务)
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Collections.Generic;
using System.Text;
using System.IO;
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class REST
Json.xaml
<UserControl x:Class="Silverlight20.Communication.Json"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Width="600">
<TextBox x:Name="txtMsgJson" Margin="5" />
<TextBox x:Name="txtMsgJson2" Margin="5" />
</StackPanel>
</UserControl>
Json.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
namespace Silverlight20.Communication
2、调用 REST 服务,返回 XML 数据
REST.cs(WCF创建的REST服务)
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Collections.Generic;
using System.Text;
using System.IO;
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class REST
Xml.xaml
<UserControl x:Class="Silverlight20.Communication.Xml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Width="600">
<TextBox x:Name="txtMsgXml" Margin="5" />
<TextBox x:Name="txtMsgXml2" Margin="5" />
</StackPanel>
</UserControl>
Xml.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.IO;
namespace Silverlight20.Communication
3、调用 REST 服务,返回 Rss/Atom 数据
Proxy.aspx.cs(返回指定的url地址的内容的服务)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Proxy : System.Web.UI.Page
RssAtom.xaml
<UserControl x:Class="Silverlight20.Communication.RssAtom"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" >
<TextBox x:Name="txtMsgRss" Width="600" Margin="5" />
<StackPanel Orientation="Horizontal">
<ListBox x:Name="list" Width="300" Margin="5" SelectionChanged="list_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title.Text}"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock x:Name="detail" Width="300" Margin="5" Text="{Binding Summary.Text}" TextWrapping="Wrap" />
</StackPanel>
</StackPanel>
</UserControl>
RssAtom.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using System.IO;
using System.ServiceModel.Syndication;
namespace Silverlight20.Communication
相关文章推荐
- 稳扎稳打Silverlight(19) - 2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
- 稳扎稳打Silverlight(19) - 2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
- 上接稳扎稳打Silverlight(19) - 2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
- 稳扎稳打Silverlight(19) - 2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
- 稳扎稳打Silverlight(19) - 2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
- 调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据(转)
- (转:Tonny Yang)jQuery备忘之(一):jQuery处理.Net后台返回的Xml格式与Json格式的数据的比较分析
- 如何使用PHP调用API接口( 如何POST一个JSON格式的数据给Restful服务)
- WCF服务返回JSON格式数据、配置web调用地址
- 基于JDK6的JAX-WX为客户端提供XML与JSON格式数据服务,以及客户端采用AXIS调用案例
- 稳扎稳打Silverlight(28) - 2.0通信之调用ADO.NET Data Services(数据服务)
- 稳扎稳打Silverlight(28) - 2.0通信之调用ADO.NET Data Services(数据服务)
- 稳扎稳打Silverlight(28) - 2.0通信之调用ADO.NET Data Services(数据服务)
- jQuery备忘之(一):jQuery处理.Net后台返回的Xml格式与Json格式的数据的比较分析
- ajax处理请求,以JSON数据格式返回,(json时间日期返回时对象---》日期格式)
- Android之从网络中获取数据并返回客户端的两种方式:XML格式返回与Json格式返回
- 原生JS的ajax处理json数据格式的异步请求完整例子
- spring mvc 在同一个controller 中同时返回多种格式的数据 (xml json atom)
- Ajax调用查看页面的后台返回json格式数据
- 使用 C++ 处理 JSON 数据交换格式