none
REST Service IIS-hosted POST problem (404 error)

    Question

  • Hi2all!

    When I host my service into local development server, it's  ok - large size requests POSTed correctly.
    But when I publish it to local IIS7 instance, service return 404 error, when I POST large (~22Mb) request to them

    I have following WCF REST service:
    [ServiceBehavior(IncludeExceptionDetailInFaults = true), AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed), ServiceContract]
        public partial class Service
        {
            [WebHelp(Comment = "Sample description for GetData")]
            [WebGet(UriTemplate = "GetData?param1={i}&param2={s}")]
            [OperationContract]
            public SampleResponseBody GetData(int i, string s)
            {
                if (i < 0) throw new WebProtocolException(HttpStatusCode.BadRequest, "param1 cannot be negative", null);
                return new SampleResponseBody()
                {
                    Value = String.Format("Sample GetData response: '{0}', '{1}'", i, s)
                };
            }
    
            [WebHelp(Comment = "Sample description for DoWork")]
            [WebInvoke(UriTemplate = "DoWork", Method = "POST")]
            [OperationContract]
            public SampleResponseBody DoWork(SampleRequestBody request)
            {
                return new SampleResponseBody()
                {
                    Value = String.Format("Data: {0}, Length: {1}", request.Data, request.Array.Length)
                };
            }
        }
    and SampleRequestBody is:
     public class SampleRequestBody
        {
            public string Data { get; set; }
            
            public byte[] Array { get; set; }
        }
    I want to upload big array using POST method. Because I host my service on the IIS, I change some options:
    <httpRuntime maxRequestLength="2097150" />
    Why I receive 404 error? May be, some special IIS7 options can help me workaround this issue?

    Thanks in advance!

    P.S. OS is Windows 7 RC, and IIS version is 7.5
    Monday, June 08, 2009 11:06 AM

Answers

  • I have found the reason of 404 error. IIS logs are helped me. Sub-code of 404 is 13, that means "Content length too large" (http://support.microsoft.com/kb/943891 )
    I just go to the applicationHost.config file, located here: %windir%\System32\inetsrv\config\, and add node
     <requestLimits maxAllowedContentLength="xxx" />
    to the '<requestFiltering>' section (solution from http://cutesoft.net/forums/thread/42292.aspx ). 'xxx' means the max size of request contentlength in bytes

    And now my REST WCF service, hosted in the  IIS, can serve the requests, and I can upload large amounts of data via HttpWebRequest and POST method!

    P.S. If you have x64 edition of Windows, and use 32bit file-managers such as, for example, FAR, you can't see anything in '%windir%\System32\inetsrv\config\' directory. Use Windows Explorer instead.
    Wednesday, June 10, 2009 9:20 AM

All replies

  • Hi,

    Have you enabled the tracing for that service ? You might find more information/details about the error in the service trace.

    Regards,
    Pablo.
    Pablo Cibraro - http://weblogs.asp.net/cibrax
    Monday, June 08, 2009 1:08 PM
  • Yes, I enable service tracing, and when I send smaller array (~5-7Mb), it's ok - service write trace info correctly, and give me right response.
    When I send large array (~22Mb), I have no entries in my log files.

    Because of it, I guess that IIS don't "transfer" incoming request to my WCF service, and automatically return 404 response

    I want to send big size serialized entities to my WCF REST service, hosted in IIS 7. May be, an additional IIS settings exists to support this scenario?
    Tuesday, June 09, 2009 5:57 AM
  • I have found the reason of 404 error. IIS logs are helped me. Sub-code of 404 is 13, that means "Content length too large" (http://support.microsoft.com/kb/943891 )
    I just go to the applicationHost.config file, located here: %windir%\System32\inetsrv\config\, and add node
     <requestLimits maxAllowedContentLength="xxx" />
    to the '<requestFiltering>' section (solution from http://cutesoft.net/forums/thread/42292.aspx ). 'xxx' means the max size of request contentlength in bytes

    And now my REST WCF service, hosted in the  IIS, can serve the requests, and I can upload large amounts of data via HttpWebRequest and POST method!

    P.S. If you have x64 edition of Windows, and use 32bit file-managers such as, for example, FAR, you can't see anything in '%windir%\System32\inetsrv\config\' directory. Use Windows Explorer instead.
    Wednesday, June 10, 2009 9:20 AM