Archive for May, 2011

WCF Data Services and maxReceivedMessageSize

May 9, 2011 1 comment

We have a WCF Data Service (Astoria) that uses most of the default configuration settings. Every once in a while, a client would receive the following exception:

System.Data.Services.Client.DataServiceRequestException: An error occurred while processing this request. ---> System.Data.Services.Client.DataServiceClientException: BadRequest

This exception only occurs when the client sends a large message. The default message size in WCF is 65536. Since we’re using a WCF Data Service and not a normal WCF Service, adding a WCF Data Service (.svc) to the project does not auto-generate the service/binding information in the config. To increase the message size, I needed to manually enter the service/binding information:

    <service name="MyNamespace.MyService">
      <endpoint bindingConfiguration="msgSize" address="" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler" />
      <!-- 2097152 = 2 MB-->
      <binding name="msgSize" maxReceivedMessageSize="2097152" maxBufferSize="2097152" />

The service name is the class (.svc) that inherits from System.Data.Services.DataService<T>.