title: How do you convert a pollingDuplex binding into a custom binding?
body: <p>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: </p>
  
  <blockquote>
    <p><em>"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."</em></p>
  </blockquote>
  
  <p>I found that in order to increase the MaxStringContentLength property I have to convert my pollingDuplex binding into a custom binding ( <a href="http://blogs.msdn.com/b/silverlightws/archive/2010/04/04/some-known-wcf-issues-in-silverlight-4.aspx" rel="nofollow">http://blogs.msdn.com/b/silverlightws/archive/2010/04/04/some-known-wcf-issues-in-silverlight-4.aspx</a>). My question is how can I do that? </p>
  
  <p>My pollingDuplex binding defined in the web.config file of the web service looks the following way:</p>
  
  <pre><code>&lt;pollingDuplex&gt;
    &lt;binding name="myPollingDuplex" closeTimeout="00:10:00" openTimeout="00:10:00"
      receiveTimeout="00:10:00" sendTimeout="00:10:00" duplexMode="MultipleMessagesPerPoll" /&gt;
  </code></pre>
  
  <p>The endpoint:</p>
  
  <pre><code>&lt;endpoint address="" binding="pollingDuplex" bindingConfiguration="myPollingDuplex" contract="WebApplication.Web.MainWS"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>The code on the web application side for instantiating the web service client:</p>
  
  <pre><code>this.client = new MainWSRef.MainWSClient(new PollingDuplexHttpBinding { DuplexMode = PollingDuplexMode.MultipleMessagesPerPoll },
              new EndpointAddress("http://localhost:1981/MainWS.svc"));
  </code></pre>
  
  <p>I tried the following:</p>
  
  <pre><code>&lt;customBinding&gt;
      &lt;binding name="myPollingDuplex" closeTimeout="00:10:00" openTimeout="00:10:00"
      receiveTimeout="00:10:00" sendTimeout="00:10:00"&gt;
        &lt;pollingDuplex duplexMode="MultipleMessagesPerPoll"&gt;
        &lt;/pollingDuplex&gt;
        &lt;textMessageEncoding&gt;
        &lt;readerQuotas maxDepth="32" maxStringContentLength="5242880"
        maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
          &lt;/textMessageEncoding&gt;
        &lt;security mode="TransportWithMessageCredential"&gt;
          &lt;transport clientCredentialType="None" proxyCredentialType="None"
            realm="" /&gt;
          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/customBinding&gt;
  </code></pre>
  
  <p>Endpoint:</p>
  
  <pre><code>&lt;endpoint address="" binding="customBinding" bindingConfiguration="myPollingDuplex" contract="WebApplication.Web.MainWS"/&gt;
  </code></pre>
  
  <p>The code on the web application side:</p>
  
  <pre><code>CustomBinding binding = new CustomBinding(new PollingDuplexBindingElement(), new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement());
          this.client = new MainWSRef.MainWSClient(binding, new EndpointAddress("http://localhost:1981/MainWS.svc"));
  </code></pre>
  
  <p>When I try to run the code I get the following error message:</p>
  
  <blockquote>
    <p><em>"The remote server returned an error: NotFound."</em></p>
  </blockquote>
  
  <p>Am I doing something wrong? I would appreciate any suggestions.</p>