1

我正在使用 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"));

当我尝试运行代码时,我收到以下错误消息:

“远程服务器返回错误:未找到。”

难道我做错了什么?我将不胜感激任何建议。

4

1 回答 1

0

当我指定 时,我得到了同样的错误ReceiveTimeout="02:00:00",没有它,它正在工作。我试图找出如何设置 ReveiveTimeout 而不会出错。

更新:我认为它的工作,那是我的服务器 web.config:

<customBinding>
    <binding name="SLDuplexService" receiveTimeout="02:00:00">
      <pollingDuplex duplexMode="MultipleMessagesPerPoll"
           maxPendingSessions="2147483647" maxPendingMessagesPerSession="2147483647" maxOutputDelay="00:00:05"
                     inactivityTimeout="02:00:00" />
      <binaryMessageEncoding/>
      <httpTransport transferMode="StreamedResponse"/>
    </binding>
  </customBinding>

请注意,receiveTimeout 是绑定的属性,而 inactivityTimeout 是 pollingDuplex 的属性。如果您不想在 10 分钟后出现故障通道,则必须设置两个超时。

您还必须在客户端上指定超时,这就是我的代码:

PollingDuplexHttpBinding binding = new PollingDuplexHttpBinding(PollingDuplexHttpSecurityMode.None, PollingDuplexMode.MultipleMessagesPerPoll);
            binding.InactivityTimeout = new TimeSpan(2,0,0);
            binding.ReceiveTimeout = new TimeSpan(2, 0, 0);

          _client = new SLDuplexServiceClient(binding, new EndpointAddress("http://localhost/LpSystem.ServiceInterface.Web/SLDuplexService/SLDuplexService.svc"));
于 2011-06-20T13:55:29.657 回答