Search code examples
c#iisodatawcf-data-services

Sending >48k to a WCF Data Service (OData) 413 error


I have a problem in that my scenario requires that I send potentially large files to a WCF data service. There appears to be a 48k limit for an HTTP request by default with IIS though this can be changed to a much large value via configuration. However this is a security feature to prevent DoS attacks. Also, I don't have any control over the IIS server deployed to even though the installation process might be able to set an initial value for this.

The data being sent is already zipped and generally will be lower than 48k, so possibly a bit of an edge case, but potentially a user loses a lot of work if they cannot upload their data.

I thought about sending the data up in chunks but then I am losing this functionality:

context.SaveChanges(SaveChangesOptions.ReplaceOnUpdate | SaveChangesOptions.Batch)

Any idea of options? WCF data services not suitable for this, anything else, traditional web service? Can the above still be achieved using alternate code but the same technology. I'm stuck with having to send the data through a service.


Solution

  • I found the solution to my issue by choosing to configure IIS 7 using the Web.Config for the WCF Data Service. I used webHttpBinding

    <system.serviceModel>
        <bindings>
            <webHttpBinding>
                <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
           </webHttpBinding>
         </bindings>
    .....
    

    The value maxReceivedMessageSize, expressed in bytes, has a default value of 64KB to limit exposure to denial of service attacks - set this to a reasonable value.