string apPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
I have a WCF service hosted on IIS that gets called from a web application. The WCF service is used for uploading/downloading files to and from a server.
For files, less than 50 KB upload/download works. However – when the file size exceeds 50 KB, it fails. No error message is displayed on the client application.
Step 1: Collect and review WCF traces
We started with configuring the WCF verbose level tracing for the service and client (web app).
For more information on configuring WCF tracing please see the link – https://msdn.microsoft.com/en-us/library/ms733025%28v=vs.110%29.aspx
After the issue was reproduced, we found that no traces were generated for the Service, but we had a set of trace for the client application.
In the traces we could find the following.
<ExceptionType>System.ServiceModel.ProtocolException, System.ServiceModel, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The remote server returned an unexpected response: (413) Request Entity Too Large.</Message>
Since we did not have any WCF trace come up for the service, it seems that the request from client never made it to the WCF layer of the service and must have gotten blocked in the IIS itself.
Step 2: Check IIS Request filtering
The first thing I checked was “IIS Request Filtering” features setting for the WCF application.
To do this, open IIS Manager. Select your application.
In the Features view you will see “Request Filtering”.
Open this feature and on the right hand panel you will find “Edit Feature Settings”
Maximum Allowed Content Length is an Optional U-Int attribute.
It specifies the maximum length of content in a request, in bytes. The default value is
30000000, which is approximately 28.6MB.
This value was already set to 28.6 MB for the customer, so we could be sure that this feature was not responsible for blocking the incoming upload/download requests.
Step 3: Check “UploadReadAheadSize” in IIS
After some research I found out there is a setting present in the IIS – “UploadReadAheadSize” that prevents upload and download of data greater than 49KB. The value present by default is 49152 bytes and can be increased up to 4 GB.
The UploadReadAheadSize property establishes the number of bytes a Web server will read into a buffer and pass to an ISAPI extension. This occurs once per client request. The ISAPI extension receives any additional data directly from the client. The range is from 0 to &HFFFFFFFF (4 GB).
For more details on this property please check the URL – https://msdn.microsoft.com/en-us/library/ms525310%28v=vs.90%29.aspx
To navigate to this setting, use the following steps:
- Launch “Internet Information Services (IIS) Manager”
- Expand the Server field
- Expand Sites
- Select the site your application is in.
- In the Features section, double click “Configuration Editor”
- Under “Section” select: system.webServer>serverRuntime
For my case, customer had maximum file size less than 50 MB, so we set it to 52428800 i.e. 50 MB.
Please note that the value is in Bytes.
This resolved the issue for us and file uploads and downloads worked fine.