Recently I worked with a WCF web service that is hosted in IIS7, and I used one of the service methods to send a byte array that contains a picture. This works well with small size images, but when I am trying to upload a larger picture, the WCF service returns an error: (413) Request Entity Too Large. I got the same error a month ago when I was developing an ASP.NET web application that is hosted on IIS 7 over SSL. In that case, there was no file upload on the page. It occurred when I am accessing the web pages that are having a grid view control with a large amount of pagination. The same pages worked fine on HTTP but not on HTTPS. In both scenarios, I Googled and found out different solutions.
In the second scenario, the error occurred because of the size of the page, it is very big, and it caused to request entry body become larger when you are submitting the page.
What happens is if you have a website with SSL and "Accept Client Certificates" enabled, HTTP requests are limited to the
UploadReadAheadSize of the site. To resolve this, you have to increase the
UploadReadAheadSize (Default size 48kb).
appcmd.exe set config -section:system.webserver/serverruntime
/uploadreadaheadsize: 1048576 /commit:apphost
WCF by default limits messages to 64KB to avoid DOS attack with a large message. By default, it sends
byte as base64 encoded string, and it increases the size of the message (33% increase in size). Therefore, if the uploaded file size is ~larger than 48KB, then it raises the above error. (48KB * 1.33 = ~64KB) (N.B.: you can use MTOM – Message Transmission Optimization Mechanize to optimize the message)
By modifying the "
maxReceivedMessageSize" in the Web.config file to accept large messages, you can solve this issue.
<readerQuotas ... />