Saturday, September 15, 2012

Another "The maximum string content length quota (8192) has been exceeded while reading XML data." issue with WCF and Silverlight 4

Another "The maximum string content length quota (8192) has been exceeded while reading XML data." issue with WCF and Silverlight 4

I have no trouble retrieving a large amount of data, but sending it back to the service displays this error. I've tried adding the element to both the web.config and servicereferences.clientconfig and it's not recognized in either. At one point I got a message about adding readerQuotas to bindingElementExtensions, but I can't find anything useful on how to do this. I found posts saying I had to modify the devenv.exe.config and such, but doing that hosed VS. I've been trying to solve this for two days so any help would be appreciated.

edit: here's the binding section of the web.config:

<bindings>   <customBinding>     <binding name="QaRiM.Web.Service1.customBinding0">       <binaryMessageEncoding />       <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />     </binding>   </customBinding> </bindings> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"   multipleSiteBindingsEnabled="true" /> <services>   <service name="QaRiM.Web.Service1">     <endpoint address="" binding="customBinding" bindingConfiguration="QaRiM.Web.Service1.customBinding0"       contract="QaRiM.Web.Service1" />     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />   </service> </services> 

and the servicereferences.clientconfig:

<configuration>     <system.serviceModel>         <bindings>             <customBinding>                 <binding name="CustomBinding_Service1">                     <binaryMessageEncoding />                     <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />                 </binding>             </customBinding>         </bindings>         <client>             <endpoint address="http://localhost:36533/Service1.svc" binding="customBinding"                 bindingConfiguration="CustomBinding_Service1" contract="ServiceReference1.Service1"                 name="CustomBinding_Service1" />         </client>     </system.serviceModel> </configuration> 

Both were generated by VS.

Answers & Comments...

Answer: 1

You are simply missing the configuration for the maximum string content length.

Add this to your binding attributes (client and server)

<readerQuotas maxStringContentLength="2147483647" /> 

Sorry, I didn't realize that this child element is located under the encoding being used when using a custom binding, it appears to bebinaryMessageEncoding in your example. If not, try the other encodings with the setting.

<bindings>     <customBinding>         <binding name="QaRiM.Web.Service1.customBinding0">                               <binaryMessageEncoding>                 <readerQuotas maxStringContentLength="2147483647"/>             </binaryMessageEncoding>         </binding>     </customBinding> </bindings> 
by : Jabhttp://stackoverflow.com/users/29676

Answer: 2

edit: This saved an incomplete draft, sorry

  1. Synchronizing the service/client definitions is what you've done but it's definitely imperative that they match.
  2. Are you sure you need custom binding? Have you tried using ws(Dual)HttpBinding as a base?
  3. This post may be of interest: http://stackoverflow.com/questions/2164065/silverlight-3-wcf-service-configuration-getting-maxreceivedmessagesize-error, specifically the httpRuntime maxRequestLength="2147483647" setting.
  4. You may need to set maxBufferPoolSize and maxItemsInObjectGraph. The config in the linked SO post pretty much maxed everything out.
  5. I don't know if you use the ChannelFactory client proxy method or the service reference method but you may wish to go the former route. In debug sessions I was finding certain values from the config weren't being applied as I had thought but my short term memory on the subject is rather lost now.
  6. Related to #5 somewhat, you can run into WCF Test Client issues where the test client is using default bindings that you're not prepared for.
  7. Another post that may be of interest: http://www.haveyougotwoods.com/archive/2008/04/14/wcf-message-streaming.aspx

Streaming is likely your best bet on the client side to keep from the blocking nature of buffered transferMode. I don't know the specifics of how big the data will be consistently but your service will behave a little nicer on the client end if you went that route. A good primer on configuring just the client side for streaming can be found here: http://systemmetaphor.blogspot.com/2009/05/using-wcf-to-transfer-large-data-files.html.

Hopefully some combination of the above helps

by : w0rd-drivenhttp://stackoverflow.com/users/134335

Answer: 3

Have you tried setting the maxStringContentLength within the config for the service? In my situation, setting it on the service allowed for the Silverlight client to use the desired value for maxStringContentLength.

One note is that if you are allowing longer strings, but don't adjust the maxReceivedMessageSize, than this can cause issues as well. The maxReceivedMessageSize does need to be controlled on both the service and the client, as one will not inherit the values from another.

by : Damienhttp://stackoverflow.com/users/888605

Answer: 4

if The maximum string content length quota (8192) has been exceeded while reading XML data." is ignoring your web.config settings EVEN after you set you can also solve the problem in your code by creating an instance of XmlDictionaryReaderQuotas and setting the MaxStringContentLength to 2147483647

then just use the instance of XmlDictionaryReaderQuotas seen here as mycreatedreaderquota

 XmlDictionaryReaderQuotas mycreatedreaderquota = new XmlDictionaryReaderQuotas();         mycreatedreaderquota.MaxStringContentLength = 2147483647;          XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(stream, mycreatedreaderquota); 
by : miles ercolanihttp://stackoverflow.com/users/1427140




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog