9

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

            MaxBufferSize = int.MaxValue,
            MaxReceivedMessageSize = int.MaxValue,
1
  • I was getting 413 Request Entity Too Large error on ASP.NET Web API project. using config.MaxReceivedMessageSize = int.MaxValue; helped me Commented Jun 19, 2014 at 13:27

4 Answers 4

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but I want to host in Asp.Net. There used to be a WebApiConfiguration class
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!!!
15
+25

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

1 Comment

this is for the request not response.
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.

Comments

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.