In another post, I mentioned the common way of solving (413) Request Entity Too Large error. However, If you are using WCF and seeing this error, you may need to go extra mile to solve this issue.
While trying to upload files that are bigger than 64 KB, we came across this error. Unfortunately, the usual fix (increasing uploadReadAheadSize and maxRequestEntityAllowed values) didn’t help.
In the dump file, we saw this error:
Exception Type : System.ServiceModel.ProtocolException Message: 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.
As the error above mentions, this issue occurs because the request size is bigger than the MaxReceivedMessageSize for WCF.
Solution for WCF 413 Request Entity Too Large error
In order to solve this problem, you will need to increase MaxReceivedMessageSize value for your web service. However, this may get tricky and cause you to spend a lot of time because there are two different MaxReceivedMessageSize parameters:
- MaxReceivedMessageSize in System.ServiceModel.Configuration.BasicHttpBindingElement
- MaxReceivedMessageSize in System.ServiceModel.Channels.HttpTransportBindingElement
Resources you will find will recommend editing your web.config like the following example:
<basicHttpBinding> <binding name="basicHttpBinding_Portal" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"> <readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647"/> </binding> </basicHttpBinding>
This configuration will increase the MaxReceivedMessageSize in System.ServiceModel.Configuration.BasicHttpBindingElement
You should increase the MaxReceivedMessageSize in System.ServiceModel.Channels.HttpTransportBindingElement as well. Here is the way to do it in web.config:
<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>
You can also do it through the code as explained in this document.
Note 1: For some cases, removing the name from basicHttpBinding also fixes the issue (name=”basicHttpBinding_Portal”)
Note 2: While trying to figure out this issue, your application may further break (not showing a table etc.) after adding maxBufferSize to your web.config. This happens because maxBufferSize is not supported for wsHttpBinding. Event ID 3 “ServiceActivationException: Unrecognized attribute ‘maxBufferSize'” error mentions this issue.
1 thought on “WCF service shows 413 Request Entity Too Large error if uploading files over 64 KB”
Dear Mr. Sahin
I have been fighting with this error for over two months. I have an application that has a wcf web service and a simple web form GUI. The wcf interacts with google speech to text APIs and gets back a text transcription of the audio file sent to it from the GUI. I did the fix in basicHttpbinding settings in the wcf and it works in local host mode but not when the app is deployed to the web server. It comes back with the error – “some error happened, file data couldn’t be sent” – which unfortunately is not helpful at all.
I tried the HttpTransportBindingElement fix in the wcf but it didn’t run even in the local host mode. Do you have any concrete examples of web.config in the service (wcf)?
Thanks much in advance.