suing
suing

Reputation: 2878

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,

Upvotes: 9

Views: 35154

Answers (4)

David Neira
David Neira

Reputation: 145

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;

Upvotes: 2

Justin Saraceno
Justin Saraceno

Reputation: 2516

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;

Upvotes: 19

lolporer
lolporer

Reputation: 419

first i would have done this configuration in the WCF App.config

<endpoint address ="" binding="basicHttpBinding" bindingConfiguration="basicHttp" contract="AddSubService.IService1">
      <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>

    <!-- Metadata Endpoints -->
    <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
    <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>

</services>

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

Then try updaeting the reference in the ASP.NET side which is calling the WCF in the web.config check that the endpoint has changed to the same.

Upvotes: 4

Kasey Speakman
Kasey Speakman

Reputation: 4641

You may want to look at httpRuntime section in web.config of your ASP.NET application. They are not named exactly the same, but there may be an analog for what you're trying to do. For instance:

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="16384" requestLengthDiskThreshold="16384"/>
  </system.web>
</configuration>

Note: Int32.MaxValue is 2,147,483,647

Upvotes: 15

Related Questions