【问题标题】:How do you convert a pollingDuplex binding into a custom binding?如何将 pollingDuplex 绑定转换为自定义绑定?
【发布时间】:2011-06-17 13:09:59
【问题描述】:

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

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

“远程服务器返回错误:NotFound。”

我做错了吗?如有任何建议,我将不胜感激。

【问题讨论】:

    标签: c# .net wcf silverlight-4.0 pollingduplexhttpbinding


    【解决方案1】:

    当我指定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"));
    

    【讨论】:

      猜你喜欢
      • 2015-03-15
      • 2011-03-13
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-17
      • 2012-03-21
      相关资源
      最近更新 更多