Compartir a través de


WCF: Sending large file to WCF fails with “404 Not Found” Error

 

WCF: Sending large file to WCF fails with “404 Not Found” Error

 

Problem Description

I have a WCF service which accept the file from client but throws an error if the file size is more than 50 MB. If you try to pass a file which has size bigger than 30 MB, you will encounter with following error:

 

 

Demo:

To demonstrate the issue and resolution I created a WCF service with a custom binding as shown below:

 

I will host this service at IIS and will consume it through web application which will be passing files to this service for various sizes. As soon as the size of the service more than 30 MB you will encounter with the error.

Troubleshooting steps:

To understand the root cause of this issue we need to collect following data from WCF service and the client:

1- WCF traces from client and server where the service is hosted

2- System.Net traces from the client and server side

After analyzing the traces you will not find the request reaching to WCF service as request claims that service test/service1.svc exists at it records 404. This means request is getting filtered somewhere before to that.

Let’s analyze the client side System.Net traces now. Search for “Exception” in the traces and then track the socket where exception is recorded.

  

Expand the post the request details at line number-198. This will show you the SOAP envelop and complete communication details. This will actually contain an error message that will be in broken strings. When you will compile the broken strings into one you will be able to see this message like shown below:

“Request filtering is configured on the Web server to deny the request because the content length exceeds the configured value.

This is a security feature. Do not change this feature unless the scope of the change is fully understood. You can configure the IIS server to reject requests whose content length is greater than a specified value. If the request's content length is greater than the configured length, this error is returned. If the content length requires an increase, modify the configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength setting.”

Below image shows you the error message in System.Net traces.

 

 

Solution:

Once you are able to see the error message in the System.Net traces, you need to review the settings for the maxAllowedContentLength setting. This value can be set at two levels:

1- IIS Level – This will change the value for all the applications. Default value is 30000000 B.

2- Application Level (In our case at WCF service level). If you don’t mention this it will be working with default value of IIS 30000000 B.

We will change it at our service so will go for second approach and will declare this value in the web.config as shown below:  

    <system.webServer>

                <security>

                                <requestFiltering>

                                               <requestLimits maxAllowedContentLength="102400000" />

                                </requestFiltering>

                </security>

    </system.webServer>

 Above setting will allow you to upload the files up to 100 MB.

 

Ashutosh Tripathi (MSFT)

Microsoft India

Comments

  • Anonymous
    May 12, 2015
    Brother, My congratulations! It's exactly I needed to solve my problem. Thank's!!!

  • Anonymous
    June 17, 2015
    thanks, this solution solve my upload problem but while retrieve the saved document i cause with System.InsufficientMemoryException!! how to solve this?

  • Anonymous
    June 21, 2015
    The comment has been removed

  • Anonymous
    July 08, 2016
    thanks man!Is's solved my problem with a large List :)