views:

145

answers:

1

I have been building a Asp.net WCF web service with json format. Now I wanted to really test how its working when sending lots of data. The Content-Length of my http post is 65595. Directly when trying to connect I got error "HTTP/1.1 400 Bad Request" back. It seems like it's not even trying.

I know I'm sending valid json and what I'm sending is an array with about 1000 items, and the json for each item looks like this: {"oid":0,"am":1,"me":2,"ofooid":0,"fooid":1104,"sync":1,"type":1,"id":1443,"date":"2009-09-24"}

If I just delete one of the items in the array so the total content-length is 65484 it works perfect. So it seems like it's a magic limit around there somewhere. Is it Asp.net that limit the size of the request, and how can I change the max size if that's the case?

My Web.Config file looks like, and I think I should set the maximum value here somewhere but I just don't know where:

<system.serviceModel>
    <behaviors>
       <endpointBehaviors>
           <behavior name="ServiceAspNetAjaxBehavior">
                <enableWebScript  />
           </behavior>
       </endpointBehaviors>
       <serviceBehaviors>
           <behavior name="ServiceBehavior">
                <serviceDebug includeExceptionDetailInFaults="true" />
           </behavior>
       </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="ServiceBehavior" name="Service">
            <endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="Service" />
        </service>
    </services>
</system.serviceModel>
A: 

You need to increase the maxReceivedMessageSize in the binding configuration for WebHttpBinding. The default is 65536. See the WebHttpBinding configuration documentation for all of the information.

Also note that you may need to increase the ASP.NET maxRequestLength via the httpRuntime configuration. The default is 4 MB but you may need to increase:

<httpRuntime maxRequestLength="10000" />
Tuzo
Thanks, that's what I was looking for! What do you think is a good value for the maxReceivedMessageSize? I do not want to send too much data, maybe I should divide the requests into smaller size and connect several times instead?
Martin