Wednesday, May 9, 2012

An error (The request was aborted: The request was canceled.) occurred while transmitting data over the HTTP channel.

I was getting an error "An error (The request was aborted: The request was canceled.) occurred while transmitting data over the HTTP channel." when I was trying to upload / stream large file through WCF Service, the file I was using is of more than 4 MB.

When we sent small files through the service, all worked fine. However, larger files (about 4MB and higher) generated the very unhelpful http exception: (400) Bad Request. This exception occurs because the entire message is not processed.

We looked at the typical culprits of this problem like <binding> settings such as maxReceivedMessageSize and <readerQuota> values to no avail.
It turned out the real problem was not in WCF, but in IIS. HTTP communication has a size limit that you have to override if you want to send large messages to your WCF service hosted in IIS. In the config file (web.config), adjust the <httpRuntime>‘s maxRequestLength attribute to a large enough size to support your messages. The value will be an integer representing the size in Kilobytes and has about a 2GB limit. The setting looks something like this (I set mine to about 64MB):
< system.web>
       <httpRuntime maxRequestLength="65536" />
< /system.web>

If IIS is the problem, you should now be able to process messages up to the size indicated in the maxRequestLength attribute.


1 comment:

Haukur ├×├│rsson said...

Thanks! Have been scratching my head now, had already changed this setting on the website itself, but not on the website which hosts the actual WCF service. That did the trick for me!