maxReceivedMessageSize and maxBufferSize in app.config

120,075

Solution 1

You need to do that on your binding, but you'll need to do it on both Client and Server. Something like:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding maxBufferSize="64000000" maxReceivedMessageSize="64000000" />
        </basicHttpBinding>
    </bindings>
</system.serviceModel>

Solution 2

You can do that in your app.config. like that:

maxReceivedMessageSize="2147483647" 

(The max value is Int32.MaxValue )

Or in Code:

WSHttpBinding binding = new WSHttpBinding();
binding.Name = "MyBinding";
binding.MaxReceivedMessageSize = Int32.MaxValue;

Note:

If your service is open to the Wide world, think about security when you increase this value.

Solution 3

The currently accepted answer is incorrect. It is NOT required to set maxBufferSize and maxReceivedMessageSize on the client and the server binding. It depends!

If your request is too large (i.e., method parameters of the service operation are memory intensive) set the properties on the server-side, if the response is too large (i.e., the method return value of the service operation is memory intensive) set the values on the client-side.

For the difference between maxBufferSize and maxReceivedMessageSize see MaxBufferSize property?.

Solution 4

If you are using a custom binding, you can set the values like this:

<customBinding>
    <binding name="x">
        <httpsTransport maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
    </binding>
</customBinding>
Share:
120,075
Vishal I P
Author by

Vishal I P

Updated on December 19, 2020

Comments

  • Vishal I P
    Vishal I P over 3 years

    How to increase maxReceivedMessageSize and maxBufferSize parameters in app.config file to 2000000 before running the application.

  • Vishal I P
    Vishal I P about 11 years
    Thanks @mattytommo,this is what i wanted.
  • Sergey
    Sergey over 9 years
    Thank you! It works for me as well. It works even when I provide this change for client only.
  • Dan Dinu
    Dan Dinu over 9 years
    perfect, you saved me a lot of time :) ++1
  • D.R.
    D.R. over 7 years
    I don't get why this answer has so many upvotes. It is wrong, you are not required to set those values on both the client and the server. See my answer below.
  • kerbasaurus
    kerbasaurus almost 7 years
    Your little bold words are life-saving. Thanks!
  • René Schindhelm
    René Schindhelm about 5 years
    I'm not sure why we have to bother to set the limits at all. What if I don't know how large a payload's going to be (think cardinalities of 0..n)?
  • D.R.
    D.R. about 5 years
    You should always have a protection against "too large". Otherwise you're wide open to DoS attacks.
  • René Schindhelm
    René Schindhelm about 5 years
    Safety aside (which really shouldn't be neglected for public facing services), you won't know at compile-time the amount of data you might send or retrieve from a service call (think object graphs f.e.). You can only estimate. I think Large Data and Streaming is of interest, especially the chapter "Special Security Considerations for Large Data".
  • Brayan Loayza
    Brayan Loayza about 3 years
    I don't have app.config file, where i can create it?