I am having some problem while implementing Web Service through WCF. While I m passing value in WCF method from client application as a string (xml), getting error
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:XmlEntity.
The InnerException
message was
'There was an error deserializing the object of type System.String. 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 249, position 19.'.
I have tried to change the value of maxStringContentLength in client web.configuration file but error is remains same. Kindly try to find out the solution asap.
Ashish, Darin means that you should've created a basicHttpBinding to override and increase the value of maxStringContentLength to 2147483647. Can you confirm whether you've configured you endpoint to use the same binidng with bindingConfiguration attribute. For example, you've created a binding like this,
<basicHttpBinding>
<binding name="HandleLargeMessage" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
You can configure endpoint to use above binding configuration like this, (please note the bindingConfiguration
attribute)
<endpoint
address="....."
binding="basicHttpBinding" bindingConfiguration="HandleLargeMessage"
contract="xxx" />
Can you confirm whether you've already done that? very likely that doesn't seem to be the case here.
If you've already followed this and would like to confirm whether it's used, capture WCF traces for service and client application at verbose level and check the activities in Construct Host at sevice and Construct channel at client application.
Try increasing this value on both the server and the client:
<binding
name="myBinding"
maxReceivedMessageSize="2147483647">
<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
As always with WCF, here is the programmatic alternative to increase the MaxStringContentLength.
BasicHttpBinding binding = new BasicHttpBinding();
binding.ReaderQuotas.MaxStringContentLength = 2147483647
host.AddServiceEndpoint(contract, binding, address);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With