返回“稳扎稳打Silverlight 3.0系列文章索引”
介绍
Silverlight 3.0 通信的新增功能
二进制XML通信 - 与 WCF 服务间通信,可以使用二进制 XML 传递数据(提高传输性能)
本地连接 - 允许客户端的两个 Silverlight 程序之间直接进行通信(不用通过服务端)
在线DEMO
http://www.cnblogs.com/webabcd/archive/2009/08/04/1538238.html
示例
1、以二进制 XML 传递数据的演示
服务端(WCF)
BinaryXmlService.svc
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Text;
namespace Silverlight30.Service
{
/**//// <summary>
/// 一个简单的 WCF 服务
/// </summary>
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class BinaryXmlService
{
[OperationContract]
public string Hello(string name)
{
return "Hello: " + name;
}
}
}
Web.config
<system.serviceModel>
<bindings>
<customBinding>
<binding name="customBinding0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="Silverlight30.Service.BinaryXmlServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Silverlight30.Service.BinaryXmlServiceBehavior"
name="Silverlight30.Service.BinaryXmlService">
<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
contract="Silverlight30.Service.BinaryXmlService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>