derek.thompson

I am developing a web service using WCF. When using a XMLReader to read an xml document, I recieve the following error:

Error in deserializing body of reply message for operation 'Get'. 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. Line 157, position 114. ---> System.Xml.XmlException: 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 have the following in App.config:
<bindings>
<wsHttpBinding>
<binding name="publisherBinding">
<readerQuotas maxStringContentLength="16384" />
</binding>
</wsHttpBinding>
</bindings>

It appears that the quota is not being retrieved from the config file, as the error message is telling me the quota is 8192. When I try to create an XmlDictionaryReaderQuotas, I recieve this error:

The type or namespace name 'XmlDictionaryReaderQuotas' could not be found (are you missing a using directive or an assembly reference )

I am including this using statements:
using System.Xml;
using System.Runtime.Serialization;

I need to increase this MaxStringContentLength property somehow. If anyone can tell me what I am doing wrong, it would be appricated. I would rather have the value in the configuration work than to set the quota programatically, if possible. Thanks in advance.




Re: Windows Communication Foundation (Indigo) XMLReader maximum string content length quota

James Osborne - MSFT

Is this error showing up on the service side And is the App.config being used there

As for setting them via code, I think this is the method for doing that:

Code Snippet

CustomBinding binding = new CustomBinding(new WSHttpBinding());

binding.Elements.Find<TextMessageEncodingBindingElement>().ReaderQuotas.MaxStringContentLength = 123456;

-James





Re: Windows Communication Foundation (Indigo) XMLReader maximum string content length quota

derek.thompson

James,

Thanks for replying.

This error is showing up on the service side, and App.config is being used there.




Re: Windows Communication Foundation (Indigo) XMLReader maximum string content length quota

James Osborne - MSFT

It's really odd that the settings on the binding aren't being picked up by the service. How are you loading the binding settings to the service endpoint Do you reference that binding in the config file If so, would you mind posting the whole config file Or are you constructing the binding in code, passing the binding name from config

-James





Re: Windows Communication Foundation (Indigo) XMLReader maximum string content length quota

derek.thompson

James,

I am referencing the binding in the config file.

Here is the serviceModel section of App.config:

<system.serviceModel>
<services>
<service name="Publishers.PublisherService" behaviorConfiguration="MEX">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Publishers/PublisherService" />
</baseAddresses>
</host>
<endpoint address="PublisherService" binding="wsHttpBinding" bindingConfiguration="publisherBinding" contract="Publishers.IService" />
<endpoint address="MEX" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MEX">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="publisherBinding">
<readerQuotas maxStringContentLength="16384" />
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>

Thanks




Re: Windows Communication Foundation (Indigo) XMLReader maximum string content length quota

David-v

Derek, James,

I am having exactly the same problem. I got the error mentioned here and after changing my web.config file:

Code Snippet

<binding name="NetTcpBinding_TestService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" transferMode="Buffered">

<readerQuotas maxDepth="32" maxStringContentLength="20000000"

maxArrayLength="20000000" maxBytesPerRead="4096" maxNameTableCharCount="20000000" /></binding>

I still get the maxlength error of 8192 characters.

In code I have checked if the setting is read by doing this before the call is executed:

Code Snippet

int maxStringContentLength = ((System.ServiceModel.NetTcpBinding)(base.Endpoint.Binding)).ReaderQuotas.MaxStringContentLength;

return base.Channel.UpdateTestDto(TestDto);

When I read out the maxStringContentLength, it says 20000000. But when the method UpdateTestDto is called I get the error saying the maxStringContentLength is limited to 8192.

Any ideas or solutions

thanks,

David





Re: Windows Communication Foundation (Indigo) XMLReader maximum string content length quota

Christian Weyer

Yep, this is a known behavior 'by design':

http://blogs.msdn.com/drnick/archive/2006/08/10/More-Binding-Polymorphism.aspx






Re: Windows Communication Foundation (Indigo) XMLReader maximum string content length quota

David-v

I have tried everything that I found on the internet to solve this issue. Making the changes to web.config and app.config, adding the maximum string lenght quota did not fix the issue.

Derek, did you finally solve your problem and how did you solve it

thanks,

David





Re: Windows Communication Foundation (Indigo) XMLReader maximum string content length quota

Christian Weyer

David,

what problem are you exactly facing What is the scenario and how does your config look like






Re: Windows Communication Foundation (Indigo) XMLReader maximum string content length quota

Garnet

Hi Derek,

I had a simillar problem where I'm using a custom binding. The resolution was to add the textMessageEncoding element and set the maxStringContentLength property there:

<customBinding>

<binding name="SomeBinding">

<textMessageEncoding>

<readerQuotas maxDepth="10000" maxStringContentLength="21892"

maxArrayLength="16384" maxBytesPerRead="24096" maxNameTableCharCount="16384" />

</textMessageEncoding>

</customBinding>





Re: Windows Communication Foundation (Indigo) XMLReader maximum string content length quota

David-v

Christian,

sorry it took so long to answer your question. One good thing though. I fixed the problem. My configuration is a webserver running asp.net and a webservice running as a windows service. Communication between the webserver and webservice was giving the problem.

As stated here and in other forums, I needed to change both the web.config and app.config of my solution. This was one of the first things I did, but it did not work.

This morning I woke up and realized that I was changing the wrong app.config in my solution . When I run my solution, it runs a servicehost to load my services and I was not changing anything in the config of the servicehost. When I applied the changes in the app.config of the servicehost, it finally worked. No more errors.

The bug was in my head this time . Conclusion, changing the config files works the way it should, as long as you change the right files.

anyway, thanks for your help and time.

David