27
votes

My call to my WCF web service is failing with System.Net.WebException: The request failed with HTTP status 413: Request Entity Too Large.

Checking Fiddler, I see that I'm sending:

Content-Length: 149839

Which is over 65KB.

Enabling WCF tracing on the server, I see:

System.ServiceModel.ProtocolException: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

Adding this property doesn't solve the issue.

I've tried with just that property, and (later) with various others that posts have suggested. Here's what I have currently (on the server):

<basicHttpBinding>

  <binding name="PricerServiceSoap"
    closeTimeout="00:10:00" openTimeout="00:10:00"
    receiveTimeout="00:10:00" sendTimeout="00:10:00"
    maxBufferSize="2147483647"    
    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">

    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
      maxArrayLength="2147483647" maxBytesPerRead="2147483647"
      maxNameTableCharCount="2147483647" />
  </binding>

</basicHttpBinding>

My sole endpoint (under <client>) is:

<endpoint address="/NetPricingService/Service.asmx"
  binding="basicHttpBinding" bindingConfiguration="PricerServiceSoap"
  contract="Pricing.PricerService.PricerServiceSoap"
  name="PricerServiceSoap" />

I've also added:

<dataContractSerializer maxItemsInObjectGraph="2147483647"/>

under <behavior>.

I've even run (for IIS 7):

%windir%\system32\inetsrv\appcmd set config "WebServicesDev/PricingService"
-section:requestFiltering -requestLimits.maxAllowedContentLength:104857600
-commitpath:apphost

Nothing makes any difference.

One catch is that this is a WCF service meant to replace an older ASMX service. The service skeleton was generated with svcutil from existing WSDL. I can't change the client configurations (and the clients are in multiple languages). My test client project imported the service with Add Web Reference (under Add Service Reference / Advanced), so I have no WCF configuration. However, the test client works if I point it at the older ASMX service.

How can I fix or diagnose this?

Additional info

If I use the Microsoft Service Configuration Editor to generate the config (setting maxReceivedMessageSize and maxBufferSize), it works. The problem is that the endpoint is then specified under <service>, and it won't let me specify the /NetPricingService/Service.asmx relative address. If I edit the bindings in the svcutil-generated config (where the endpoint is under <client>), it doesn't work with large requests.

6

6 Answers

25
votes

The answer was staring me in the face.

The config generated by svcutil was for the client. I was using it on the server.

I was editing the bindings for the endpoints specified under <client>, which made absolutely no difference to the service.

Adding a proper <service> endpoint and setting the maxReceivedMessageSize and maxBufferSize on its binding resolved the issue.

25
votes

I had a similar problem. For me, the problem was that my endpoint did not explicitly name the binding using bindingConfiguration and so must have been using some default one somewhere.

I had:

<webHttpBinding>
    <binding 
        name="myXmlHttpBinding" 
        maxReceivedMessageSize="10485760" 
        maxBufferSize="10485760">
        <readerQuotas 
            maxDepth="2147483647" 
            maxStringContentLength="2147483647" 
            maxArrayLength="2147483647" 
            maxBytesPerRead="2147483647" 
            maxNameTableCharCount="2147483647"/>
        <security mode="None"/>
    </binding>
</webHttpBinding>

and my endpoint defined as:

<service 
    name="blah.SomeService">
    <endpoint 
        address="" 
        behaviorConfiguration="WebHttpBehavior" 
        binding="webHttpBinding" 
        contract="blah.ISomeService">

        <identity>
            <dns value="localhost"/>
        </identity>
    </endpoint>
</service>

It worked once I changed the endpoint to:

  <service name="blah.SomeService">
    <endpoint address="" 
        behaviorConfiguration="WebHttpBehavior" 
        binding="webHttpBinding" 
        bindingConfiguration="myXmlHttpBinding" 
        contract="blah.ISomeService">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
  </service>
5
votes

I also had this problem and realized in fiddler that the max Content-Length that was working ended up being 30000000.

After verifying that my WCF configuration was correct I found an article suggesting a modification to the IIS setting, Request Filtering.

Large file upload failure for Web application calling WCF service – 413 Request entity too large

  1. Open IIS Manager
  2. Select your application
  3. Select the Request Filtering icon.
  4. Select Edit Feature Settings... (Right Panel)
  5. Adjust the Maximum allowed content length (Bytes) Default Appears to be 30000000

or web.config file example

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="50000000" />
    </requestFiltering>
  </security>
</system.webServer>
1
votes

tried things from 10 different blogs and my coworker figured it out. we had to add a basicHttpsBinding section inside of in addition to the basicHttpBinding section. We have a webapi service calling wcf. the webapi method was catching the entity too large error when it called the wcf service method. This change was applied in the web.config file of the wcf service.

1
votes

None of the suggestions worked for me. What solved the issue was to increase the MaxReceivedMessageSize in System.ServiceModel.Channels.HttpTransportBindingElement

There are two different MaxReceivedMessageSize parameters:

  • MaxReceivedMessageSize in System.ServiceModel.Configuration.BasicHttpBindingElement
  • MaxReceivedMessageSize in System.ServiceModel.Channels.HttpTransportBindingElement

In the dump file, I saw that it was failing because of the limitation in HttpTransportBindingElement

Adding this to my web.config fixed the issue:

<customBinding>
   <binding closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00">
      <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" useDefaultWebProxy="true" transferMode="Buffered" />
   </binding>
</customBinding>

Source: WCF service shows 413 Request Entity Too Large error when uploading files over 64 KB

0
votes

Add this solve it for me:

    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_Example"
 maxBufferSize="2147483647" 
maxReceivedMessageSize="2147483647">
            </binding>
        </basicHttpBinding>
    </bindings>