Advertisement
The data I am sending through the service is very large and very soon, I got the following exception message:
"... There was an error deserializing the object of type MyType. 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. .."
By default when using Visual Studio and WCF, your app.config will be injected with some servicemodel settings Using XMLSerializer on a Type received from my wsdl, I get the error, however, I am not passing it through to the server, just client side serialization, I get the same error.
WCF injects xml configuration into your app.config as below.
[code:xml] < system.serviceModel > < services > < service behaviorConfiguration ="PublishingService.ProductServiceBehavior" name ="PublishingService.PublishingService" > < endpoint address ="" binding ="wsHttpBinding" contract ="OxiNet.Publishing.ITarget" > < identity > < dns value ="localhost" /> </ identity > </ endpoint > ............cut short [/code]
But it did not contain a vital attribute on the endpoint. "bindingConfiguration="WSHttpBinding_ITarget"
[code:xml] < system.serviceModel > < services > < service behaviorConfiguration ="PublishingService.ProductServiceBehavior" name ="PublishingService.PublishingService" > < endpoint address ="" binding ="wsHttpBinding" contract ="OxiNet.Publishing.ITarget" bindingConfiguration ="WSHttpBinding_ITarget > bindingConfiguration="WSHttpBinding_ITarget" < identity > < dns value ="localhost" /> </ identity > </ endpoint > ............cut short [/code]
AND it also required a bindings node, of which I am not sure how much of it, it actually uses. My service fails if its not present.
[code:xml] < system.serviceModel > < bindings > < wsHttpBinding > < binding name ="WSHttpBinding_ITarget" > < readerQuotas maxStringContentLength ="2147483647" /> </ binding > </ wsHttpBinding > </ bindings > < services > < service behaviorConfiguration="PublishingService.ProductServiceBehavior" ..... cut short [/code]
then your client can utilize a config or code way of dealing with the size.
[code:xml]< configuration > < system.serviceModel > < bindings > < wsHttpBinding > < binding name ="WSHttpBinding_ITarget" closeTimeout ="00:01:00" openTimeout ="00:01:00" receiveTimeout ="00:10:00" sendTimeout ="00:01:00" bypassProxyOnLocal ="false" transactionFlow ="false" hostNameComparisonMode ="StrongWildcard" maxBufferPoolSize ="524288" maxReceivedMessageSize =" 2147483647" messageEncoding ="Text" textEncoding ="utf-8" useDefaultWebProxy ="true" allowCookies ="false" > < readerQuotas maxDepth ="2147483647" maxStringContentLength ="2147483647" maxArrayLength ="2147483647" maxBytesPerRead ="4012" maxNameTableCharCount ="8192" /> < reliableSession ordered ="true" inactivityTimeout ="00:10:00" enabled ="false" /> < security mode ="Message" > < transport clientCredentialType ="Windows" proxyCredentialType ="None" realm ="" /> < message clientCredentialType ="Windows" negotiateServiceCredential ="true" algorithmSuite ="Default" establishSecurityContext ="true" /> </ security > </ binding > </ wsHttpBinding > </ bindings > </ system.serviceModel > </ configuration > [/code]
or within code you can get a "Max" version of the XmlDictionaryReaderQuotas configuration.
[code:c#]
EndpointAddress endPoint = new EndpointAddress("http://localhost:8731/ProductService" );
WSHttpBinding binding = new WSHttpBinding();
XmlDictionaryReaderQuotas readerQuotas = XmlDictionaryReaderQuotas.Max;
binding.ReaderQuotas = readerQuotas;
PublishingService.TargetClient target = new PublishingService.TargetClient(binding,endPoint);
[/code]
Read: WCF MaxStringContentLength and Config