Geeks With Blogs

Vitaly Dilmukhametov

Not long ago I notice interesting “feature” of WCF REST, hosted in the IIS7: when size of data from client exceeds some value, service broke the connection.
I created test service, where I could reproduce this issue, using WCF REST Starter Kit (you can download here actual release, Preview 2). One of service's method is:

[WebHelp(Comment = "Sample description for DoWork")]
[WebInvoke(UriTemplate = "DoWork", Method = "POST")]
public SampleResponseBody DoWork(SampleRequestBody request)
    return new SampleResponseBody()
        Value = String.Format("Data: {0}, Length: {1}", request.Data, 

So, this method has 1 parameter, which is passed by the POST method. Code of SampleRequestBody entity:

public class SampleRequestBody
    public string Data { get; set; }
    public byte[] Array { get; set; }


I set large quotas and 10 minutes request timeout in the binding configuration (in web.config file) for my test service:

    <binding name="webBinding"
             maxBufferSize="152428800" maxReceivedMessageSize="152428800"
      <readerQuotas maxStringContentLength="152428800"


After that I successfully host my test service in the local development server, and it work normal. Here screenshot of client console application. How you can see, service side received 30Mb file successfully.


Then I host my test service in the IIS7. And when I try to call service method from the client, I get an exception:


I check Windows EventLog, but it don’t contain any items about my service. Next step is to allow IIS7 accept large size requests. You can do that with maxRequestLength attribute:

<httpRuntime maxRequestLength="xxx"/>


where xxx is maximum request size in KB.

But after that service still can’t serve requests normally. And I noticed, that exception on client side was changed:


I got 404 error on my client side. Windows EventLogs still don’t had any useful info, and I decided enable logging of my service. When I try to call service, it log is empty. And I think, that requests from client is dropped by something before they achieve the service, i.e. by IIS7. I check IIS logs, and found, that IIS reply 404 error with subcode 13. It’s means, that incoming request is too large. I search, and locate some interesting option. File %windir%\System32\inetsrv\config\applicationHost.config contain <requestFiltering> section. I add following parameter:

<requestLimits maxAllowedContentLength="xxx" />


where xxx is max size of request. And when I set it, service work normal.

One trick with applicationHost.config: in the x64 version of Windows this file is not visible from 32bit file managers such as FAR Manager and other. Windows Explorer show it normally. I think, that 32bit applications is redirected to some other place, that doesn’t contain applicationHost.config. For example, VS 2008 devenv.exe is 32bit app, and you can’t edit applicationHost.config file in Visual Studio. Use notepad for edit.

So there are 3 steps to allow large size requests:

1. deal with binding configuration: set maxReceivedMessageSize, maxBufferSize etc. parameters;

2. set maxRequestLength attribute of <httpRuntime> in the web.config;

3. set max request size in the <requestFiltering> section and <requestLimit> element in the  %windir%\System32\inetsrv\config\applicationHost.config;

Posted on Sunday, July 12, 2009 2:14 PM Deployment , WCF , IIS7 , REST , hosting | Back to top

Comments on this post: WCF REST services: hosting in the IIS7

# re: WCF REST services: hosting in the IIS7
Requesting Gravatar...
Clear steps given here helped me to track down where exactly I needed to configure. Thanks
Left by Chathuranga Wijeratna on Aug 25, 2009 5:17 AM

Your comment:
 (will show your gravatar)

Copyright © Vitus | Powered by: