简体   繁体   中英

How do you convert a pollingDuplex binding into a custom binding?

I am using pollingDuplex binding for the communication between my Silverlight web application and my WCF web service. Till now it worked fine until I tried to send large amounts of data from the web application to the web service in the form of an xmlString. Then I got the error message:

"The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'SendUserSelection'. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader."

I found that in order to increase the MaxStringContentLength property I have to convert my pollingDuplex binding into a custom binding ( http://blogs.msdn.com/b/silverlightws/archive/2010/04/04/some-known-wcf-issues-in-silverlight-4.aspx ). My question is how can I do that?

My pollingDuplex binding defined in the web.config file of the web service looks the following way:

<pollingDuplex>
  <binding name="myPollingDuplex" closeTimeout="00:10:00" openTimeout="00:10:00"
    receiveTimeout="00:10:00" sendTimeout="00:10:00" duplexMode="MultipleMessagesPerPoll" />

The endpoint:

<endpoint address="" binding="pollingDuplex" bindingConfiguration="myPollingDuplex" contract="WebApplication.Web.MainWS"/>

The code on the web application side for instantiating the web service client:

this.client = new MainWSRef.MainWSClient(new PollingDuplexHttpBinding { DuplexMode = PollingDuplexMode.MultipleMessagesPerPoll },
            new EndpointAddress("http://localhost:1981/MainWS.svc"));

I tried the following:

<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:

<endpoint address="" binding="customBinding" bindingConfiguration="myPollingDuplex" contract="WebApplication.Web.MainWS"/>

The code on the web application side:

CustomBinding binding = new CustomBinding(new PollingDuplexBindingElement(), new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement());
        this.client = new MainWSRef.MainWSClient(binding, new EndpointAddress("http://localhost:1981/MainWS.svc"));

When I try to run the code I get the following error message:

"The remote server returned an error: NotFound."

Am I doing something wrong? I would appreciate any suggestions.

I get the same error when I specify the ReceiveTimeout="02:00:00" , without that, it is working. I try to find out how to set the ReveiveTimeout without an error.

Update: I think its working, thats my Server 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>

Note that the receiveTimeout is a property of the binding whereas inactivityTimeout is a property of pollingDuplex. Both timeouts have to be set if you don't want a faulted channel after 10 minutes.

You also have to specify the timeouts on the client, thats my code:

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"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM