Firstly, a disclaimer: I don’t have a lot of experience working with AJAX enabled WCF services, and from reading some of Rick Strahl’s posts on using JQuery with ASP.NET, I’m doing things in a really hackish and terrible manner. Hopefully my mistakes won’t impact the usefulness of this short tip.
When working with JQuery and AJAX enabled WCF services, I recently encountered the following error, through Firebug and Fiddler:
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.
This is caused by WCF webHttpBinding default having fairly draconion limitations on XML message length and depth. This thread on MSDN helped diagnose the problem, however it didn’t do much to help me solve my particular problem. Ultimately, I stumbled upon the solution quite accidentally.
Firstly, as per the MSDN thread, you need to add the custom binding configuration underneath the
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="bindingConfiguration">
<readerQuotas maxDepth="32" maxStringContentLength="2048000" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</webHttpBinding>
</bindings>
..
</system.serviceModel>
At first I thought this was a custom binding, and tried to replace the service endpoint binding to the custom binding defined above, however this was causing an “System.ServiceModel.ServiceActivationException” exception.
The above binding declaration is actually a configuration for the webHttpBinding. As such, you need to add the BindingConfiguration property onto your service endpoint, along side your binding declaration. This is as follows:
<service behaviorConfiguration="Your.Service.Behavior"
name="Your.Service.Name">
<endpoint address="" behaviorConfiguration="Your.Behavior.Configuration"
binding="webHttpBinding" bindingConfiguration="bindingConfiguration" contract="Your.Service.Contract" />
</service>
This will allow you to send larger messages to your WCF services via AJAX, and get on with creating applications.
