9

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

            MaxBufferSize = int.MaxValue,
            MaxReceivedMessageSize = int.MaxValue,
suing
  • 2,808
  • 2
  • 16
  • 18
  • I was getting `413 Request Entity Too Large` error on ASP.NET Web API project. using `config.MaxReceivedMessageSize = int.MaxValue;` helped me – SharpCoder Jun 19 '14 at 13:27

4 Answers4

19

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;
radu florescu
  • 4,315
  • 10
  • 60
  • 92
Justin Saraceno
  • 2,516
  • 1
  • 18
  • 16
  • Thanks, but I want to host in Asp.Net. There used to be a WebApiConfiguration class – suing Feb 26 '12 at 23:10
  • That seem like a likely solution, I'll have to test it. Ya right 2gb resource in a REST service is crazy. We have coarse grained services which I hate that are ~ 5 mb per message. Yuck!!! – suing Mar 02 '12 at 20:35
15

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

Kasey Speakman
  • 4,511
  • 2
  • 32
  • 41
4

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.

lolporer
  • 419
  • 4
  • 5
2

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;
Sebastian Lenartowicz
  • 4,695
  • 4
  • 28
  • 39
David Neira
  • 125
  • 2
  • 5