I've written a WCF service with .NET 4.0, which is hosted on my Windows 7 x64
Ultimate system with IIS 7.5.
One of the service methods has an 'object' as argument and I'm trying to send a byte[] which contains a picture.
As long as the file size of this picture is less then approx. 48KB, all goes well. But if I'm trying to upload a larger picture, the WCF service returns an error: (413) Request Entity Too Large.
So ofcourse I've spent 3 hours Googling the error message and every topic I've seen about this subject suggests raising the 'uploadReadAheadSize' property.
So what I've done is using the following commands (10485760 = 10MB):
"appcmd.exe set config -section:system.webserver/serverruntime/uploadreadaheadsize: 10485760 /commit:apphost"
"cscript adsutil.vbs set w3svc/<APP_ID>/uploadreadaheadsize 10485760"
I've also used IIS Manager to set the value by opening the site and going to "Configuration Editor" under Management. Unfortunately I'm still getting the Request Entity Too Large error and it's getting really frustrating!
So does anybody know what else I can try to fix this error?
For me, setting the
uploadReadAheadSize
to int.MaxValue also fixed the problem, after also increasing the limits on the WCF binding.It seems that, when using SSL, the entire request entity body is preloaded, for which this metabase property is used.
For more info, see:
The page was not displayed because the request entity is too large. iis7
If you're running into this issue despite trying all of the solutions in this thread, and you're connecting to the service via SSL (e.g. https), this might help:
http://forums.newatlanta.com/messages.cfm?threadid=554611A2-E03F-43DB-92F996F4B6222BC0&#top
To summarize (in case the link dies in the future), if your requests are large enough the certificate negotiation between the client and the service will fail randomly. To keep this from happening, you'll need to enable a certain setting on your SSL bindings. From your IIS server, here are the steps you'll need to take:
netsh http show sslcert
. This will give you your current configuration. You'll want to save this somehow so you can reference it again later.netsh http delete sslcert <ipaddress>:<port>
where<ipaddress>:<port>
is the IP:port shown in the configuration you saved earlier.netsh http add sslcert
here (MSDN) but in most cases your command will look like this:netsh http add sslcert ipport=<ipaddress>:<port> appid=<application ID from saved config including the {}> certhash=<certificate hash from saved config> certstorename=<certificate store name from saved config> clientcertnegotiation=enable
If you have multiple SSL bindings, you'll repeat the process for each of them. Hopefully this helps save someone else the hours and hours of headache this issue caused me.
EDIT: In my experience, you can't actually run the
netsh http add sslcert
command from the command line directly. You'll need to enter the netsh prompt first by typingnetsh
and then issue your command likehttp add sslcert ipport=...
in order for it to work.In my case I had to increase the "Maximum received message size" of the Receive Location in BizTalk. That also has a default value of 64K and so every message was bounced by BizTAlk regardless of what I configured in my web.config
This helped me to resolve the problem (one line - split for readability / copy-ability):
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 setreaderQuotas
.I was receiving this error message, even though I had the
max
settings set within the binding of my WCF service config file:It seemed as though these binding settings weren't being applied, thus the following error message:
.
The Problem
I realised that the
name=""
attribute within the<service>
tag of theweb.config
is not a free text field, as I thought it was. It is the fully qualified name of an implementation of a service contract as mentioned within this documentation page.If that doesn't match, then the binding settings won't be applied!
I hope that saves someone some pain...