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.