Wcf maxStringContentLength configuration not working

We are trying to send a large xml string to a service method in WCF, and we get an error

The maximum length of the quota string content (8192) was exceeded reading XML data.

The error implies an increase in maxstringcontentlength , although we were not sure that we should do this on the client side or on the server side, or both. We tried using both, but we still seem to get the error. I am going to publish the client and service configuration below. I assume there is a problem with one or both of them so that this does not work.

Any suggestions?

Customer:

 <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_ITESTService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647" /> <security mode="None" /> </binding> </basicHttpBinding> </bindings> <client> <endpoint name="BasicHttpBinding_ITESTService" address="http://localhost/TESTService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITESTService" contract="TESTService.ITESTService" /> </client> </system.serviceModel> 

Server:

 <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_Service1" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647" /> <security mode="None" /> </binding> </basicHttpBinding> </bindings> <services> <service name="TESTService"> <endpoint name="BasicHttpBinding_Service1" address="http://localhost/TESTService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Service1" contract="ITESTService" /> </service> </services> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> 
+4
source share
4 answers

This thread explains in detail how to correctly specify the binding parameters on the server and client in order to change MaxStringContentLength.

This other thread also gives a clear and efficient answer to using readerQuotas.

0
source

Try adding a default binding (without specifying a name). Add readerQuota settings to this binding.

You can also remove the readerQuota settings from the named binding that you are actually using.

This worked for me (although I'm not sure why readerQuotas on the correct named binding are ignored by WCF)

+2
source

The default bind function worked for me. I tried to set the maxStringContentLength value in a named WebHttpBinding, but for some reason it did not get WCF. finally, I continued with D.Tiemstra, after which I began to work.

  <webHttpBinding> <binding maxReceivedMessageSize="2147483647" > <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> </webHttpBinding> 
+1
source

I would use these values ​​for WCF configuration (programmatically):

 Security = { Mode = SecurityMode.None}, CloseTimeout = TimeSpan.MaxValue, OpenTimeout = TimeSpan.MaxValue, SendTimeout = TimeSpan.FromMinutes(5), ReceiveTimeout = TimeSpan.FromMinutes(5), MaxBufferSize = 2147483647, MaxBufferPoolSize = 524288, MaxReceivedMessageSize = 2147483647, ReaderQuotas = new XmlDictionaryReaderQuotas { MaxDepth = 32, MaxStringContentLength = 8192, MaxArrayLength = 16384, MaxBytesPerRead = 4096, MaxNameTableCharCount =1638 } 
+1
source

Source: https://habr.com/ru/post/1337561/


All Articles