Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does one increase maxStringContentLength in order to get WCF to pass large strings?

Okay so I've set up and tested a nice little WCF service. The client creates a string and passes it into a method on the service and the service then saves it as a file. Works perfectly with small amounts of test data but when I try it with what it's supposed to do - pass some serialized .net objects - it falls over, with the error

The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 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

So I goggle this and find that the MaxStringContentLength property should be set on a "readerQuotas" tag within the tag of the config file, like this:

     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

So I change it. I change it on the App.config file of my client. I change it on the App.config file and the Web.config file of my server. I change it in the App.config file of my unit test project. And none of it works - I keep getting the same error.

Interesting, and frustratingly, when I fired up WcfClient.exe to have a look at my service, connected to it and has a look at the config file (Client.dll.config) I was gobsmacked to find that this auto-generated file contained none of my changes and has reset to:

  <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />

I have no idea where it's getting these values from - nowhere in my entire solution are these being set. So it must be using defaults, but I don't understand why it's using defaults when I've provided custom Config files at both server and client.

Can anyone help me untangle this?

like image 421
Bob Tway Avatar asked Feb 18 '11 16:02

Bob Tway


1 Answers

1) Is it possible that your endpoint isn't properly referencing the custom binding? Could you post your binding and endpoint sections?

2) WcfTestClient doesn't use your service or client configs to set its own configuration. You'll need to manually edit the Client.dll.config with SvcConfigEditor to set up the WcfTestClient client binding data before executing the service.

You can persist your WcfTestClient configuration changes if you look at the Tools -> Options menu. For more information on WcfTestClient, check this out: http://msdn.microsoft.com/en-us/library/bb552364.aspx

like image 98
Robert Scheibler Avatar answered Sep 20 '22 06:09

Robert Scheibler