仅作为个人记录:
今天研究了一下WCF Duplex双工通道在SilverLight中进行通讯的问题,在网上找到了两篇MSDN的关于用这两者来实现一个在线聊天程序 (service: http://msdn.microsoft.com/zh-cn/library/cc645027(VS.95).aspx and client: http://msdn.microsoft.com/zh-cn/library/cc645028(VS.95).aspx)。按照这里给出的代码,编译测试后老是出现文章标题中出现的问题,查了很多资料,但大部分都是提到通过更改web.config改变允许传输的字节的多少,这些方法都不能解决这个问题。后来将
this.AddServiceEndpoint( typeof(IDuplexService), new CustomBinding( pdbe, new TextMessageEncodingBindingElement( MessageVersion.Soap11, System.Text.Encoding.UTF8), new HttpTransportBindingElement()), "");
改为
this.AddServiceEndpoint( typeof(IDuplexService), new CustomBinding( pdbe, new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement()), "");然后将Message returnMessage =Message.CreateMessage(MessageVersion.Soap11, "Silverlight/IDuplexService/Receive", text);改为:Message returnMessage =Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "Silverlight/IDuplexService/Receive", text);这个问题就解决了,奇怪的是msdn里还专门提到了Silverlight仅支持Soap11的,但现在改为Soap12WSAddressing10不但解决了这个问题,而且用起来一切正常,还没弄清楚原因