If you are working on wcf rest service and getting below error:
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.
Then there are two solutions.
1. Check your webconfig/Appconfig and Edit system.serviceModel section or check the below code:
please copy the below code and replace "♣" with '<' or '>'sign.
=================================================================
♣system.serviceModel♣
♣services♣
♣service behaviorConfiguration="TestServiceBehavior" name="TestWcfService.TestService"♣
♣endpoint address="" binding="webHttpBinding" contract="TestWcfService.ITestService" behaviorConfiguration="WebBehavior" bindingConfiguration="StreamedRequestWebBinding"♣
♣identity♣
♣dns value="localhost"/♣
♣/identity♣
♣/endpoint♣
♣endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/♣
♣/service♣
♣/services♣
♣bindings♣
♣webHttpBinding♣
♣binding name="StreamedRequestWebBinding" bypassProxyOnLocal="true" useDefaultWebProxy="false" maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="StreamedRequest"♣
♣readerQuotas maxStringContentLength = "2147483647" /♣
♣/binding♣
♣/webHttpBinding♣
♣/bindings♣
♣client♣
♣endpoint name="Default" address="http://localhost:2461//TestService.svc" binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding"
contract="ServiceReference.IYourService" /♣
♣/client♣
♣behaviors♣
♣serviceBehaviors♣
♣behavior name="TestServiceBehavior"♣
♣serviceMetadata httpGetEnabled="true"/♣
♣dataContractSerializer maxItemsInObjectGraph="2147483647"/♣
♣serviceDebug includeExceptionDetailInFaults="true"/♣
♣/behavior♣
♣/serviceBehaviors♣
♣endpointBehaviors♣
♣behavior name="WebBehavior"♣
♣webHttp/♣
♣/behavior♣
♣/endpointBehaviors♣
♣/behaviors♣
♣/system.serviceModel♣
2. If the problem is still there then 2nd way is by coding and the coding part is :
WebHttpBinding binding =
new WebHttpBinding(WebHttpSecurityMode.None);
binding.MaxBufferSize = Int32.MaxValue;
binding.MaxBufferPoolSize = Int32.MaxValue;
binding.MaxReceivedMessageSize = Int32.MaxValue;
XmlDictionaryReaderQuotas
readerQuotas = new XmlDictionaryReaderQuotas();
readerQuotas.MaxStringContentLength
= int.Parse("2147483647");
readerQuotas.MaxArrayLength = int.Parse("2147483647");
binding.ReaderQuotas =
readerQuotas;
using
(WebChannelFactory<ITestService> cf = new
WebChannelFactory<ITestService>(binding,new
Uri(Convert.ToString(ConfigurationManager.AppSettings["ServiceUrl"]))))
{
ITestService
channel = cf.CreateChannel();
String
result = channel.YOURMETHOD();
Response.Write(result);
}