Maximum request length exceeded in WCF

▼魔方 西西 提交于 2019-11-29 11:39:49

You might have to set the readerQuotas for the binding as shown below:

            WSHttpBinding binding1 = new WSHttpBinding();
            binding1.MaxBufferPoolSize = 2147483647;
            binding1.MaxReceivedMessageSize = 2147483647;            

            var myReaderQuotas1 = new XmlDictionaryReaderQuotas();
            myReaderQuotas1.MaxStringContentLength = 2147483647;
            myReaderQuotas1.MaxDepth = 2147483647;
            myReaderQuotas1.MaxArrayLength = 2147483647;
            myReaderQuotas1.MaxBytesPerRead = 2147483647;
            myReaderQuotas1.MaxNameTableCharCount = 2147483647;
            binding1.GetType().GetProperty("ReaderQuotas").SetValue(binding1, myReaderQuotas1, null);

The reason is that setting quotas on a binding that has already been created has no effect.

Also you would need to consider increasing your "MaxItemsInObjectGraph" value of the DataContractSerializer on both client and server to a large value.

Change the following setting in web.config

 <configuration> 
    <system.web> 
        <httpRuntime maxRequestLength="xxxx" /> 
    </system.web> 
</configuration> 

xxxx is the value in KB you want to set it to.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!