Friday 27 July 2012

WCF Binding Configuration for Maximum Data Size

Below is the WCF binding configuration to allow maximum data size. Please bear in mind not to put these settings on public services as these settings will make your application vulnerable to security attacks.
<bindings>
  <wsHttpBinding>
    <binding name="myBindingName" maxReceivedMessageSize="2147483647" 
        closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" >
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
          maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      . . .
    </binding>
  </wsHttpBinding>
</bindings>
maxReceivedMessageSize, maxDepth, maxStringContentLength, maxArrayLength, maxBytesPerRead, maxNameTableCharCount attributes accept integer values so we can put the maximum integer value which is 2147483647.

According to MSDN documentation, increasing this value alone is not enough in ASP.NET compatible mode. The maxRequestLength attribute value of httpRuntime needs to be increased as well. Its default value is 4096 KB. The maximum value for .NET Framework 2.0 or above is 2GB (2097151).
<system.web>
  <httpRuntime maxRequestLength="2097151" />
  . . .
</system.web>

Note that I also increase the timeout attributes to 10 minutes.


For more information:
webHttpBinding on MSDN
readerQuotas on MSDN

No comments: