Wednesday, February 08, 2012

Large data requests with WCF

Large requests to or from a WCF service can fail because of limitations set in the web.config of the service.

If you get either of the following errors:

  • An existing connection was forcibly closed by the remote host.
  • HTTP 400 error

when sending or receiving a large amount of data, but it works fine on smaller amounts of data try making these changes in the web.config:

xml version="1.0" encoding="utf-8"?>  <configuration>    <system.web>      <httpRuntime maxRequestLength="2147483647"/>    system.web>    <system.serviceModel>      <behaviors>        <serviceBehaviors>          <behavior>            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>          behavior>        serviceBehaviors>      behaviors>      <bindings>        <basicHttpBinding>          <binding name="BasicHttpBinding_ServiceName"
          closeTimeout="00:10:00" openTimeout="00:10:00"
          receiveTimeout="00:10:00" sendTimeout="00:10:00"
          allowCookies="false" bypassProxyOnLocal="false"          hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647"          maxReceivedMessageSize="2147483647" messageEncoding="Text"
          textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">            <readerQuotas maxDepth="32"
            maxStringContentLength="2147483647"
            maxArrayLength="2147483647"
            maxBytesPerRead="2147483647"            maxNameTableCharCount="16384" />            <security mode="None">              <transport clientCredentialType="None" proxyCredentialType="None" realm="" />              <message clientCredentialType="UserName" algorithmSuite="Default" />            security>          binding>        basicHttpBinding>      bindings>      <protocolMapping>        <add scheme="http" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_ServiceName "/>      protocolMapping>    system.serviceModel>  configuration>


No comments:

Post a Comment