我正在使用 pollingDuplex 绑定来进行 Silverlight Web 应用程序和 WCF Web 服务之间的通信。直到现在它工作正常,直到我尝试以 xmlString 的形式将大量数据从 Web 应用程序发送到 Web 服务。然后我收到错误消息:
“格式化程序在尝试反序列化消息时抛出异常:反序列化操作'SendUserSelection'的请求消息正文时出错。读取XML数据时已超出最大字符串内容长度配额(8192)。此配额可以通过更改来增加创建 XML 阅读器时使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性。”
我发现为了增加 MaxStringContentLength 属性,我必须将 pollingDuplex 绑定转换为自定义绑定(http://blogs.msdn.com/b/silverlightws/archive/2010/04/04/some-known-wcf-问题-silverlight-4.aspx)。我的问题是我该怎么做?
我在 Web 服务的 web.config 文件中定义的 pollingDuplex 绑定如下所示:
<pollingDuplex>
<binding name="myPollingDuplex" closeTimeout="00:10:00" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00" duplexMode="MultipleMessagesPerPoll" />
端点:
<endpoint address="" binding="pollingDuplex" bindingConfiguration="myPollingDuplex" contract="WebApplication.Web.MainWS"/>
用于实例化 Web 服务客户端的 Web 应用程序端的代码:
this.client = new MainWSRef.MainWSClient(new PollingDuplexHttpBinding { DuplexMode = PollingDuplexMode.MultipleMessagesPerPoll },
new EndpointAddress("http://localhost:1981/MainWS.svc"));
我尝试了以下方法:
<customBinding>
<binding name="myPollingDuplex" closeTimeout="00:10:00" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00">
<pollingDuplex duplexMode="MultipleMessagesPerPoll">
</pollingDuplex>
<textMessageEncoding>
<readerQuotas maxDepth="32" maxStringContentLength="5242880"
maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</customBinding>
端点:
<endpoint address="" binding="customBinding" bindingConfiguration="myPollingDuplex" contract="WebApplication.Web.MainWS"/>
Web应用端的代码:
CustomBinding binding = new CustomBinding(new PollingDuplexBindingElement(), new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement());
this.client = new MainWSRef.MainWSClient(binding, new EndpointAddress("http://localhost:1981/MainWS.svc"));
当我尝试运行代码时,我收到以下错误消息:
“远程服务器返回错误:未找到。”
难道我做错了什么?我将不胜感激任何建议。