Vahe
Vahe

Reputation: 1841

C#/ASP.NET - The remote server returned an unexpected response: (413) Request Entity Too Large

I am trying to establish a response from a remote service. Using the following section in my web.config I am getting an undesired response from web service.

The remote server returned an unexpected response: (413) Request entity too large. I tried increasing the buffer size, but am unable to get past this error.

How can I resolve this issue?

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="CustomBinding_ISalesOrderService" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <security mode="Transport"/>
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://app.vendsys2.com/VendSysAPI/v1.2/SalesOrderService.svc/VendSysAPI/v1.2/SalesReportService.svc"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding_ISalesOrderService"
        contract="SalesOrderService.ISalesOrderService" name="CustomBinding_ISalesOrderService" />
    </client>
  </system.serviceModel>

Upvotes: 1

Views: 731

Answers (1)

NtFreX
NtFreX

Reputation: 11367

If a client sends a long HTTP request the IIS worker process might receive enough data to parse request headers, but not receive the entire request entity body. When the IIS worker process detects that client certificates are required to return data to the client, IIS attempts to renegotiate the client connection. However, the client cannot renegotiate the connection because it is waiting to send the remaining request data to IIS [1]. Your problem could be just that.

Taken from Microsoft TechNet

If client renegotiation is requested, the request entity body must be preloaded using SSL preload. SSL preload will use the value of the UploadReadAheadSize metabase property, which is used for ISAPI extensions. However, if UploadReadAheadSize is smaller than the content length, an HTTP 413 error is returned, and the connection is closed to prevent deadlock. (Deadlock occurs because a client is waiting to complete sending a request entity, while the server is waiting for renegotiation to complete, but renegotiation requires that the client to be able to send data, which it cannot do).


The solution is to ensure that client is not blocked from sending the entire entity body. To do so, change the value of UploadReadAheadSize to a value larger than the content length.

The following example shows how to set the value for UploadReadAheadSize to 200KB on the Web server.

cscript adsutil.vbs set w3svc/1/uploadreadaheadsize 200

Be aware of that the UploadReadAheadSize element was removed in IIS 7 and was added as an attribute to to serverRuntime element.

Upvotes: 1

Related Questions