89

I get this exception while creating scope for few tables all those tables are huge in design

<bindings>
    <wsHttpBinding>
        <binding name="wsHttpBinding_ISyncServices" closeTimeout="00:10:00"
            openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
            transactionFlow="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
            <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                maxNameTableCharCount="2147483647" />
            <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
            <security mode="Message">
                <transport clientCredentialType="Windows"
                    proxyCredentialType="None" realm="">
                    <extendedProtectionPolicy policyEnforcement="Never" />
                </transport>
                <message clientCredentialType="Windows"
                    negotiateServiceCredential="true" algorithmSuite="Default" />
            </security>
        </binding>
    </wsHttpBinding>
</bindings>

I have made MaxReceivedMessageSize to 2147483647 but still it is giving me below exception at this line

 client.GetTableDescription(scopeName, syncTable)

The maximum message size quota for incoming messages (65536) has been exceeded.
To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

Filnor
  • 1,290
  • 2
  • 23
  • 28
Onkar
  • 891
  • 1
  • 6
  • 4
  • 1
    possible duplicate of [WCF - How to Increase Message Size Quota](http://stackoverflow.com/questions/884235/wcf-how-to-increase-message-size-quota) – RQDQ Mar 28 '11 at 13:35
  • http://stackoverflow.com/questions/884235/wcf-how-to-increase-message-size-quota – NoWar Jul 31 '14 at 13:43
  • 3
    Possible duplicate of [WCF - How to Increase Message Size Quota](http://stackoverflow.com/questions/884235/wcf-how-to-increase-message-size-quota) – Joshua Drake Mar 22 '17 at 18:02

8 Answers8

118

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.

Sebastian Zaklada
  • 2,308
  • 1
  • 14
  • 25
27

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>
KyleMit
  • 30,350
  • 66
  • 462
  • 664
Softec
  • 1,087
  • 11
  • 14
18

Updating the config didn't work for me, but I was able to edit the binding programmatically:

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;
}
KyleMit
  • 30,350
  • 66
  • 462
  • 664
Praveen Tiwari
  • 1,200
  • 1
  • 12
  • 25
13

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>
flayn
  • 5,272
  • 4
  • 48
  • 69
  • 1
    But it's true. I've had the same problem, until I've changed setting on the client. Then it was OK. – FrenkyB Oct 30 '15 at 10:38
  • 1
    If anyone will have similar problem. I've set everything up on the WCF, but I was still receiving error message. On the client I've added code below and after that, it was OK. Thanks a lot @CarrieKendall. – FrenkyB Oct 30 '15 at 11:13
  • 1
    Same settings on server side with code: BasicHttpBinding bind01 = new BasicHttpBinding();bind01.Security.Mode = BasicHttpSecurityMode.None; bind01.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;bind01.MaxReceivedMessageSize = int.MaxValue; bind01.MaxBufferPoolSize = int.MaxValue;bind01.MaxBufferSize = int.MaxValue; bind01.ReaderQuotas.MaxDepth = 32;bind01.ReaderQuotas.MaxArrayLength = int.MaxValue; bind01.ReaderQuotas.MaxStringContentLength = int.MaxValue;bind01.ReceiveTimeout = new TimeSpan(0, 10, 0); – FrenkyB Jun 28 '17 at 08:00
  • Adding maxReceivedMessageSize="2147483647 " on the client side fixed my problem. Thank you – chosenOne Thabs Nov 30 '18 at 16:49
  • I created a simple webservice which returns a whole lot of records, and was getting this error. I tried applying the solution on the server, but that did not work, so I did as suggested, and changed WCF Test Client's config, and that did it. Instead of laughing, I tried it out. Just a thought – Ricardo Appleton Oct 16 '19 at 10:03
  • Thanks! I found the comment from @CarrieKendall a bit rude, but yours and the others made up for it :) – flayn Oct 28 '19 at 12:16
12

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

RQDQ
  • 15,461
  • 2
  • 32
  • 59
7

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
Denis
  • 11,796
  • 16
  • 88
  • 150
1

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
    }
};
MichaelCleverly
  • 2,473
  • 1
  • 24
  • 33
0

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

user3499962
  • 1
  • 1
  • 2