Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure the buffer size and max message size in the ASP.NET Web API

We used to have these properties in the WCF Web API configuration.

            MaxBufferSize = int.MaxValue,
            MaxReceivedMessageSize = int.MaxValue,
like image 619
suing Avatar asked Feb 26 '12 14:02

suing


People also ask

What is Max buffer size in HTTP binding?

System. ServiceModel Basic Http Binding. Max Buffer Size Property System. Service Model Gets or sets the maximum size, in bytes, for a buffer that receives messages from the channel. The maximum size, in bytes, of a buffer that stores messages while they are processed for an endpoint configured with this binding. The default value is 65,536 bytes.

What happens if a message exceeds the max size of a buffer?

If a message exceeds the maximum value set for the buffer, it is not dropped. Instead, more memory is requested from the CLR heap and this incurs more garbage collection overhead than using the buffers. The settings for MaxBufferSize and MaxReceivedMessageSize, are local behavioral settings.

What is the maxreceivedmessagesize of the soap buffer?

For buffered messages this value is the same as MaxReceivedMessageSize. For streamed messages, this value is the maximum size of the SOAP headers, which must be read in buffered mode. The maximum size, in bytes, of the buffer. The following example sets this property to use when performing requests on the binding.

What is the maxbuffersize of a buffer?

The maximum size, in bytes, of a buffer that stores messages while they are processed for an endpoint configured with this binding. The default value is 65,536 bytes. The following example sets MaxBufferSize to 1,000,000 bytes. The value of this property can also be set in the configuration file.


2 Answers

I solve this problem making a dynamic binding before like this

BasicHttpBinding bind = new BasicHttpBinding();
bind.OpenTimeout = bind.CloseTimeout = bind.SendTimeout = bind.ReceiveTimeout = new TimeSpan(0, 30, 0);
bind.MaxBufferSize = int.MaxValue;
bind.MaxReceivedMessageSize = int.MaxValue;
like image 57
David Neira Avatar answered Nov 04 '22 03:11

David Neira


If you're self-hosting, it's part of the HttpSelfHostConfiguration class: MSDN Documentation of the HttpSelfHostConfiguration class

It would be used like this:

var config = new HttpSelfHostConfiguration(baseAddress);
config.MaxReceivedMessageSize = int.MaxValue;
config.MaxBufferSize = int.MaxValue;
like image 39
Justin Saraceno Avatar answered Nov 04 '22 03:11

Justin Saraceno