493

I have a WCF Service which returns 1000 records from database to the client. I have an ASP.NET WCF client (I have added service reference in asp.net web application project to consume WCF).

I get the following message when I run the client application:

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.

Any help? How to increase message size quota?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
bugBurger
  • 6,950
  • 9
  • 32
  • 39
  • 1
    I had the same problem but I just got an unfriendly network error 400 but the solution was the message size thingie.. – Mr W Sep 07 '11 at 12:48
  • 2
    I solved the problem by using the steps mentioned in [the link][1] [1]: http://stackoverflow.com/questions/7476853/wcf-error-maximum-number-of-items-that-can-be-serialized-or-deserialized-in-an/8656402#8656402 – Ram Dec 28 '11 at 13:23
  • Why is it set so low by default? Security? – Paul C Feb 18 '15 at 12:23
  • @Coops for security indeed. By setting a quota on the messages for example DDOS attacks are (at least a bit) harder to execute. – Peter van Kekem Aug 23 '17 at 08:27
  • Just need to update your config on server side – AbbathCL Aug 27 '21 at 17:35

13 Answers13

648

You'll want something like this to increase the message size quotas, in the App.config or Web.config file:

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

And use the binding name in your endpoint configuration e.g.

...
bindingConfiguration="basicHttp"
...

The justification for the values is simple, they are sufficiently large to accommodate most messages. You can tune that number to fit your needs. The low default value is basically there to prevent DOS type attacks. Making it 20000000 would allow for a distributed DOS attack to be effective, the default size of 64k would require a very large number of clients to overpower most servers these days.

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
Nate
  • 30,286
  • 23
  • 113
  • 184
  • 22
    Thanks..This change is needs to be made in web.config file of client application. – bugBurger May 19 '09 at 18:08
  • 8
    You may also need to change it on the server -- in the event you need to send in a large dataset as a parameter to a WCF Method. – Nate May 19 '09 at 19:08
  • 4
    Any particular reason for the message size of 20000000? – Brian Vander Plaats Jun 01 '10 at 22:22
  • 9
    Its sufficently large to accomidate most messages. You can tune that number to fit your needs. It is basically there to prevent DOS type attacks. Making it 20000000 would allow for a distributed DOS attack to be effective, the default size of 64k would require a very large number of clients to overpower most servers these day.s – Nate Jun 01 '10 at 22:49
  • 19
    For others who are interested, I read on another blog that the maximum size is 2147483647. 20000000 is a bit smaller than this number, so using the smallest number you can get away with without interrupting service makes sense. – proudgeekdad Oct 07 '10 at 16:22
  • It doesn't make sense that this is a DOS attack prevention. Wouldn't malicious clients just set this to a high value? Can't I change it on the server instead? – Neil Barnwell Feb 06 '12 at 17:25
  • @NeilBarnwell This is a configuration option on both the client and the server. – Nate Feb 06 '12 at 18:11
  • @Nate how can this be configured in extension less hosting – joshua Aug 20 '13 at 10:48
  • @Joshua I'm afraid I don't understand your question. Could you elaborate a little on what you're trying to do and what isn't working? Possibly open a new question and link it here? – Nate Aug 20 '13 at 14:18
  • 2
    With the exception message in the question (about message sizes *incoming* on the server) the *only* thing that needs to be changed to fix this particular problem is increasing `maxReceivedMessageSize` in the *server's* config file. No change in client config is necessary nor changing any other parameter. – Slauma Nov 05 '13 at 13:22
  • 5
    @Slauma It would need to be changed on the server if that incoming parameter was too large; otherwise (and more likely) the change needs to be made in the client configuration file, since it is the response of the service (not its parameter) that is too large. – Nate Nov 06 '13 at 02:44
  • Nate, you are right, I see now. The message in the question is probably thrown by the client, not by the server. I was confused because I had exactly the same message, but thrown on server side (because a *request* parameter was too large). – Slauma Nov 06 '13 at 12:12
  • I used this to solve my problem. thanks for the answer. but after the modification when I'm invoking the service using WCF Test client the same error is occurring. but the application is working as i expected. please may i know the reason..? – Hasanka Rathnayake Jun 26 '14 at 10:36
  • Its possible that you are recieving more data than you want. Since you arent using the out of bounds data,its behaving correctly. Just a thought. If you are selecting many entries out of a database and only manipulating the first few, this could be the case. – kingfrito_5005 Jul 23 '15 at 20:38
  • 1
    As @Gab pointed out: "Don't forget that the `app.config` of the execution entry point will be considered, not the one in class library project managing Web-Service calls if there is one. For example if you get the error while running unit test, you need to set up appropriate config in the testing project." – Marcus Mangelsdorf Sep 13 '15 at 23:31
  • I also changed to maximum size 2147483647, but still getting the same error any help please ? – Younis Qadir Dec 17 '15 at 11:10
  • Done all the changes as state above but getting the same error. Please help, I am stuck here – Munavvar Aug 02 '16 at 07:25
  • I test your solution for my problem but I don't get answer!! http://stackoverflow.com/questions/38856971/wcf-http-binding – Farshid Shekari Aug 10 '16 at 07:20
  • for java client where i add this – R.Anandan Mar 07 '17 at 05:01
  • i am using c# wcf service in my java application in that where i configure this MaxBufferSize – R.Anandan Mar 07 '17 at 05:33
  • @R.Anandan This is something configured on the server, if you are consuming the service its not something you will be able to change. – Nate Mar 07 '17 at 18:35
  • @Nate I set the code you provided on my `web.config`. Where do I set the `bindingConfiguration`? – Malcolm Salvador Sep 19 '17 at 01:17
  • I came back to say that the `bindingConfiguration="basicHttp"` is the exact answer people should be looking for – Jijo Nair Apr 13 '21 at 07:36
167

If you're still getting this error message while using the WCF Test Client, it's because the client has a separate MaxBufferSize setting.

To correct the issue:

  1. Right-Click on the Config File node at the bottom of the tree
  2. Select Edit with SvcConfigEditor

A list of editable settings will appear, including MaxBufferSize.

Note: Auto-generated proxy clients also set MaxBufferSize to 65536 by default.

ѺȐeallү
  • 2,887
  • 3
  • 22
  • 34
Michael Rodrigues
  • 5,057
  • 3
  • 25
  • 51
118

If you are creating your WCF bindings dynamically here's the code to use:

BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.MaxReceivedMessageSize = Int32.MaxValue;
httpBinding.MaxBufferSize = Int32.MaxValue;
// Commented next statement since it is not required
// httpBinding.MaxBufferPoolSize = Int32.MaxValue;
Community
  • 1
  • 1
Bharath K
  • 2,109
  • 1
  • 14
  • 18
49

The WCF Test Client has it's own client config.

Run the test client and scroll to the bottom. If you double click the Config File node you will see the XML representation. As you can see the maxReceivedMessageSize is 65536.

To edit this, Right Click the Config File tree node and select Edit With SvcConfigEditor. When the editor opens expand Bindings and double click the binding that was automatically generated.

You can edit all the properties here, including maxReceivedMessageSize. When you are done click File - Save.

Lastly, when you are back at the WCF Test Client window, click Tools - Options.

NOTE: Uncheck the Always regenerate config when launching services.

furier
  • 1,934
  • 1
  • 21
  • 39
Jodee Dex Page
  • 551
  • 5
  • 3
  • 2
    Probably the best answer here! – Haris Jan 24 '14 at 08:28
  • 3
    upvote because of the note to uncheck the `Always regenerate config` option. – furier Feb 17 '14 at 11:33
  • Simplest solve in my opinion. Saved me some headache. – Jared Beach Aug 26 '14 at 15:55
  • On vs2013 SvcConfigEditor is replace with Edit WCF configuration if people are looking for it. – ZoomVirus Sep 24 '14 at 11:28
  • Thank you. Been breaking my head for a while, changing the server config again and again, when the problem was with the Test Client config! – Fahad Mar 15 '15 at 09:05
  • If I change the maxReceivedMessageSize to 100.000, then refresh the service, after unchecking what u wrote in the note, it still says received message size exceeds 65536. Seems like I cant change the size, even if I save it correctly. – dezox Jul 03 '23 at 08:35
25

I found the easy way

--- right click the webconfig or app config file and click EDIT WCF CONFIGURATION and got to bingdigs ans select yore service and right side show maxReciveMessageSize give a large number ---

NC64
  • 369
  • 5
  • 12
8

I solved my issue on Bing Maps WPF on my project Using CalculateRoute (). The solution in my case was setting the maxReceivedMessageSize and maxReceivedMessageSize on attribute "httpTransport" for "customBinding" section .

I set in the applications.config file (es. myApp.config) this configuration:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IGeocodeService" />
            <binding name="BasicHttpBinding_IRouteService" />
        </basicHttpBinding>
        <customBinding>
            <binding name="CustomBinding_IGeocodeService">
                <binaryMessageEncoding />
              <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                                maxReceivedMessageSize="2147483647" allowCookies="false" authenticationScheme="Anonymous"
                                bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                                keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous"
                                realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                                useDefaultWebProxy="true" />
            </binding>
            <binding name="CustomBinding_IRouteService">
                <binaryMessageEncoding />
              <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                                maxReceivedMessageSize="2147483647" allowCookies="false" authenticationScheme="Anonymous"
                                bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                                keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous"
                                realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                                useDefaultWebProxy="true" />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGeocodeService"
            contract="BingServices.IGeocodeService" name="BasicHttpBinding_IGeocodeService" />
        <endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc/binaryHttp"
            binding="customBinding" bindingConfiguration="CustomBinding_IGeocodeService"
            contract="BingServices.IGeocodeService" name="CustomBinding_IGeocodeService" />
        <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRouteService"
            contract="BingServices.IRouteService" name="BasicHttpBinding_IRouteService" />
        <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc/binaryHttp"
            binding="customBinding" bindingConfiguration="CustomBinding_IRouteService"
            contract="BingServices.IRouteService" name="CustomBinding_IRouteService" />
    </client>
</system.serviceModel>
8

Another important thing to consider from my experience..

I would strongly advice NOT to maximize maxBufferPoolSize, because buffers from the pool are never released until the app-domain (ie the Application Pool) recycles.

A period of high traffic could cause a lot of memory to be used and never released.

More details here:

Community
  • 1
  • 1
Valerio Gentile
  • 1,071
  • 11
  • 24
8

For HTTP:

<bindings>
  <basicHttpBinding>
    <binding name="basicHttp" allowCookies="true"
             maxReceivedMessageSize="20000000" 
             maxBufferSize="20000000"
             maxBufferPoolSize="20000000">
        <readerQuotas maxDepth="200" 
             maxArrayLength="200000000"
             maxBytesPerRead="4096"
             maxStringContentLength="200000000"
             maxNameTableCharCount="16384"/>
    </binding>
  </basicHttpBinding>
</bindings>

For TCP:

<bindings>
  <netTcpBinding>
    <binding name="tcpBinding"
             maxReceivedMessageSize="20000000"
             maxBufferSize="20000000"
             maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="200"
           maxArrayLength="200000000"
           maxStringContentLength="200000000"
           maxBytesPerRead="4096"
           maxNameTableCharCount="16384"/>
    </binding>
  </netTcpBinding>
</bindings>

IMPORTANT:

If you try to pass complex object that has many connected objects (e.g: a tree data structure, a list that has many objects...), the communication will fail no matter how you increased the Quotas. In such cases, you must increase the containing objects count:

<behaviors>
  <serviceBehaviors>
    <behavior name="NewBehavior">
      ...
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
Jacob
  • 3,598
  • 4
  • 35
  • 56
  • The `maxItemsInObjectGraph` was the (quick) solution for me. But when increasing this, you should think about whether the better solution is for your application to request data in chunks, as opposed to a huge object graph that may strain resources. – Paul Mar 14 '20 at 15:54
8

I solve the problem ...as follows

    <bindings>
  <netTcpBinding>
    <binding name="ECMSBindingConfig" closeTimeout="00:10:00" openTimeout="00:10:00"
      sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647" portSharingEnabled="true">
      <readerQuotas maxArrayLength="2147483647" maxNameTableCharCount="2147483647"
          maxStringContentLength="2147483647" maxDepth="2147483647"
          maxBytesPerRead="2147483647" />
      <security mode="None" />
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="ECMSServiceBehavior">
      <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceTimeouts transactionTimeout="00:10:00" />
      <serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="100"
        maxConcurrentInstances="100" />
    </behavior>
  </serviceBehaviors>
</behaviors>
  • 21
    How does this differ from my solution? Other than you included all the irrelevant portions of your configuration as well as the relevant parts and you chose the maximum possible value instead of the 200m I chose? – Nate Apr 06 '11 at 15:48
  • 4
    Context is good too... maybe these two answers could be merged? – Jeff Jun 30 '11 at 19:08
  • 1
    is that setting be configure in server or client? – John Kenedy Dec 13 '11 at 06:23
6

For me, all I had to do is add maxReceivedMessageSize="2147483647" to the client app.config. The server left untouched.

ashilon
  • 1,791
  • 3
  • 24
  • 41
6

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_Username" maxReceivedMessageSize="20000000"          maxBufferPoolSize="20000000">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName" establishSecurityContext="false"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<client>
  <endpoint
            binding="wsHttpBinding"
            bindingConfiguration="wsHttpBinding_Username"
            contract="Exchange.Exweb.ExchangeServices.ExchangeServicesGenericProxy.ExchangeServicesType"
            name="ServicesFacadeEndpoint" />
</client>

Hemant Soni
  • 2,051
  • 4
  • 16
  • 16
  • Great for posting your answer. It is important that the "bindingConfiguration" value matches the binding name. In your example "wsHttpBinding_Username". – Bruno Bieri Dec 09 '15 at 09:06
3

Don't forget that the app.config of the execution entry point will be considered, not the one in class library project managing Web-Service calls if there is one.

For example if you get the error while running unit test, you need to set up appropriate config in the testing project.

Gab
  • 7,869
  • 4
  • 37
  • 68
0

i got this error when using this settings on web.config

System.ServiceModel.ServiceActivationException

i set settings like this:

      <service name="idst.Controllers.wcf.Service_Talks">
    <endpoint address="" behaviorConfiguration="idst.Controllers.wcf.Service_TalksAspNetAjaxBehavior"
      binding="webHttpBinding" contract="idst.Controllers.wcf.Service_Talks" />
  </service>
  <service name="idst.Controllers.wcf.Service_Project">
    <endpoint address="" behaviorConfiguration="idst.Controllers.wcf.Service_ProjectAspNetAjaxBehavior"
      binding="basicHttpBinding" bindingConfiguration="" bindingName="largBasicHttp"
      contract="idst.Controllers.wcf.Service_Project" />
  </service>
</services>

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

FARHAD AFSAR
  • 440
  • 5
  • 10
  • 4
    So, you fixed your problem by using Nate's answer and then posted it as your own. Not cool. – arcain Mar 29 '13 at 01:24
  • @arcain Nates answer was very generic, using stock names and numbers that can be expected to come up frequently. This answer was not stolen, it is simply the right answer. As there is only one correct answer, it was bound to be repeated. – kingfrito_5005 Jul 23 '15 at 20:52
  • @kingfrito_5005 The "correct" answer was already here when the answerer posted this. He pretty clearly lifted Nate's `bindings` element and reposted it as part of his answer. Those `2000000` values are pretty distinct. – arcain Jul 24 '15 at 15:05
  • @arcain, I disagree those are very standard values, my company uses them in our binding elements as well. – kingfrito_5005 Jul 24 '15 at 16:43