The maximum message size quota for incoming messages (65536) has been exceeded

不打扰是莪最后的温柔 提交于 2019-11-27 07:55:54

As per this question's answer

You will want something like this:

<bindings>
     <basicHttpBinding>
         <binding name="basicHttp" allowCookies="true"
 maxReceivedMessageSize="20000000"
 maxBufferSize="20000000"
 maxBufferPoolSize="20000000">
             <readerQuotas maxDepth="32"
 maxArrayLength="200000000"
 maxStringContentLength="200000000"/>
         </binding>
     </basicHttpBinding> </bindings>

Please also read comments to the accepted answer there, those contain valuable input.

You also need to increase maxBufferSize. Also note that you might need to increase the readerQuotas.

You need to make the changes in the binding configuration (in the app.config file) on the SERVER and the CLIENT, or it will not take effect.

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding maxReceivedMessageSize="2147483647 " max...=... />
        </basicHttpBinding>
       </bindings>
</system.serviceModel>

If you are using CustomBinding then you would rather need to make changes in httptransport element. Set it as

<customBinding> <binding ...> ... <httpsTransport maxReceivedMessageSize="2147483647"/> </binding> </customBinding>

This worked for me:

 Dim binding As New WebHttpBinding(WebHttpSecurityMode.Transport)
 binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
 binding.MaxBufferSize = Integer.MaxValue
 binding.MaxReceivedMessageSize = Integer.MaxValue
 binding.MaxBufferPoolSize = Integer.MaxValue

Making changes to config didn't help me. Following worked well tho

private YourAPIClient GetClient()
    {
        Uri baseAddress = new Uri(APIURL);
        var binding = new BasicHttpBinding();
        binding.MaxReceivedMessageSize = 20000000;
        binding.MaxBufferSize = 20000000;
        binding.MaxBufferPoolSize = 20000000;
        binding.AllowCookies = true;
        var readerQuotas = new XmlDictionaryReaderQuotas();
        readerQuotas.MaxArrayLength = 20000000;
        readerQuotas.MaxStringContentLength = 20000000;
        readerQuotas.MaxDepth = 32;
        binding.ReaderQuotas = readerQuotas;
        if (baseAddress.Scheme.ToLower() == "https")
            binding.Security.Mode = BasicHttpSecurityMode.Transport;
        var client = new YourAPIClient(binding, new EndpointAddress(baseAddress));
        return client;
    }

My solution was to use the "-OutBuffer 2147483647" parameter in my query, which is part of the Common Parameters. PS C:> Get-Help about_CommonParameters -Full

For me, the settings in web.config / app.config were ignored. I ended up creating my binding manually, which solved the issue for me:

var httpBinding = new BasicHttpBinding()
{
    MaxBufferPoolSize = Int32.MaxValue,
    MaxBufferSize = Int32.MaxValue,
    MaxReceivedMessageSize = Int32.MaxValue,
    ReaderQuotas = new XmlDictionaryReaderQuotas()
    {
        MaxArrayLength = 200000000,
        MaxDepth = 32,
        MaxStringContentLength = 200000000
    }
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!