(413) Request Entity Too Large | UploadReadAheadSize


Answer :

That is not problem of IIS but the problem of WCF. WCF by default limits messages to 65KB to avoid denial of service attack with large messages. Also if you don't use MTOM it sends byte[] to base64 encoded string (33% increase in size) => 48KB * 1,33 = 64KB

To solve this issue you must reconfigure your service to accept larger messages. This issue previously fired 400 Bad Request error but in newer version WCF started to use 413 which is correct status code for this type of error.

You need to set maxReceivedMessageSize in your binding. You can also need to set readerQuotas.

<system.serviceModel>   <bindings>     <basicHttpBinding>       <binding maxReceivedMessageSize="10485760">         <readerQuotas ... />       </binding>     </basicHttpBinding>   </bindings>   </system.serviceModel> 

I was having the same issue with IIS 7.5 with a WCF REST Service. Trying to upload via POST any file above 65k and it would return Error 413 "Request Entity too large".

The first thing you need to understand is what kind of binding you've configured in the web.config. Here's a great article...

BasicHttpBinding vs WsHttpBinding vs WebHttpBinding

If you have a REST service then you need to configure it as "webHttpBinding". Here's the fix:

<system.serviceModel>  <bindings>    <webHttpBinding>     <binding        maxBufferPoolSize="2147483647"        maxReceivedMessageSize="2147483647"        maxBufferSize="2147483647" transferMode="Streamed">     </binding>      </webHttpBinding> </bindings> 

I had the same problem and setting the uploadReadAheadSize solved it:

http://www.iis.net/configreference/system.webserver/serverruntime

"The value must be between 0 and 2147483647."

It is easily set it in the applicationHost.config-fle if you don't want to do a cmd-thing.

Its located in WindowsFOLDER\System32\inetsrv\config (2008 server).

You must open it with notepad. Do a Backup of the file first.

According to the comments in config the recommended way to unlock sections is by using a location tag:

<location path="Default Web Site" overrideMode="Allow">     <system.webServer>         <asp />     </system.webServer> </location>" 

So you can write in the bottom (since it doesn't exist before). I write maxvalue here - write your own value if you want.

<location path="THENAMEOFTHESITEYOUHAVE" overrideMode="Allow">     <system.webServer>         <asp />         <serverRuntime uploadReadAheadSize="2147483647" />     </system.webServer> </location> 

If you put it last before </configuration> for example, you know where you have it.

Hope that solves your problems. It was an SSL overhead issue for me, where too much post freezed the application, raising a (413) Request Entity Too Large error.


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable