The maximum string content length quota (8192) resolution is exceeded when the XML data is read by a Web Service or WCF call

Source: Internet
Author: User
Tags xml reader

1. Service when invoking service

When we use a WEB service or WCF service, we often convert the data we read into a string type (XML format), and when the amount of data reaches a certain amount, the following exception occurs:

error : The formatter threw an exception when attempting to deserialize a message: An error occurred while attempting to deserialize the parameter http://tempuri.org/(namespace): The innerexception message is "deserialize the object exception, read the XML Data, the maximum string content length quota (8192) is exceeded. You can increase this quota by changing the Maxstringcontentlength property of the XmlDictionaryReaderQuotas object that is used when you create the XML reader.

2. Causes and Solutions

When WCF transmits big data, because of the security mechanism of WCF itself, it restricts the transfer size of client and server resources, and generates an exception when the transmitted data exceeds the upper limit.

sending Big data: Resolving on WCF service side

nettcpbinding binding = new nettcpbinding ();

Binding. Maxreceivedmessagesize= 2147483647 (change this number);

receive Big data: Resolve in WCF Client

nettcpbinding binding = new nettcpbinding ();

Binding. Readerquotas = new XmlDictionaryReaderQuotas ()

{maxstringcontentlength = 2147483647 (change this number)};

When the Web Service is called, on the binding proxy side, add the following basichttpbinding:

There are two ways of handling:
The first: The binding parameter is passed in when called.

    

New BasicHttpBinding (basichttpsecuritymode.none)                   int . MaxValue,                    int. MaxValue,                    new  System.Xml.XmlDictionaryReaderQuotas ()                   2147483647 }                  new dltest. Servicereference2.cs_webservicesoapclient (binding);  

The second method, change the config file with client config

Increase Readerquotas node control under binding node

<?xml version= "1.0" encoding= "Utf-8"?><configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name= "Cs_webservicesoap" > <readerqu OTAs maxdepth= "maxstringcontentlength=" 8192000 "maxarraylength=" 16384000 "maxbytesperread=" 4096000 "maxnametablecharcount=" 16384000 "/> </binding> <binding name=" Cs_webservi CeSoap1 "><readerquotas maxdepth= "maxstringcontentlength=" 8192000 "maxarraylength=" 16384000 "M Axbytesperread= "4096000" maxnametablecharcount= "16384000"/>              </binding> <binding name= "Cs_webservicesoap2"/> </basichttpbinding > </bindings> <client> <endpoint address= "Http://10.0.0.251:100/WebService/CS_W Ebservice.asmx "binding=" BasicHttpBinding "bindingconfiguration=" Cs_webservicesoap "contract = "Servicereference1.cs_webservicesoap" name= "Cs_webservicesoap"/> <endpoint address= "http://localhost:90                /webservice/cs_webservice.asmx "binding=" BasicHttpBinding "bindingconfiguration=" CS_WebServiceSoap1 " contract= "Servicereference2.cs_webservicesoap" name= "Cs_webservicesoap1"/> <endpoint address= "h Ttp://localhost:3383/webservice/cs_webservice.asmx "binding=" BasicHttpBinding "bindingconfiguration=" CS_Web ServiceSoap2 "contract=" Servicereference3.cs_webservicesoap "name=" Cs_webservicesoap2 "/> </cl Ient> </system.Servicemodel></configuration> 

  

The maximum string content length quota (8192) resolution is exceeded when the XML data is read by a Web Service or WCF call

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.