title: Large WCF web service request failing with (400) HTTP Bad Request
body: <p>I've encountered this apparently common problem and have been unable to resolve it.</p>
  <p><strong>If I call my WCF web service with a relatively small number of items in an array parameter (I've tested up to 50), everything is fine.</strong></p>
  <p><strong>However if I call the web service with 500 items, I get the Bad Request error.</strong></p>
  <p>Interestingly, I've run <a href="http://www.wireshark.org/" rel="nofollow noreferrer">Wireshark</a> on the server and it appears that the request isn't even hitting the server - the 400 error is being generated on the client side.</p>
  <p><strong>The exception is:</strong></p>
  <blockquote>
  <p>System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (400) Bad Request. ---&gt; System.Net.WebException: The remote server returned an error: (400) Bad Request.</p>
  </blockquote>
  <p><strong>The <code>system.serviceModel</code> section of my client config file is:</strong></p>
  <pre class="lang-xml prettyprint-override"><code> &lt;system.serviceModel&gt;
      &lt;bindings&gt;
          &lt;wsHttpBinding&gt;
              &lt;binding name=&quot;WSHttpBinding_IMyService&quot; closeTimeout=&quot;00:01:00&quot;
                  openTimeout=&quot;00:01:00&quot; receiveTimeout=&quot;00:10:00&quot; sendTimeout=&quot;00:01:00&quot;
                  bypassProxyOnLocal=&quot;false&quot; transactionFlow=&quot;false&quot; hostNameComparisonMode=&quot;StrongWildcard&quot;
                  maxBufferPoolSize=&quot;524288&quot; maxReceivedMessageSize=&quot;2147483647&quot;
                  messageEncoding=&quot;Text&quot; textEncoding=&quot;utf-8&quot; useDefaultWebProxy=&quot;true&quot;
                  allowCookies=&quot;false&quot;&gt;
                  &lt;readerQuotas maxDepth=&quot;32&quot; maxStringContentLength=&quot;8192&quot; maxArrayLength=&quot;2147483647&quot;
                      maxBytesPerRead=&quot;4096&quot; maxNameTableCharCount=&quot;16384&quot; /&gt;
                  &lt;reliableSession ordered=&quot;true&quot; inactivityTimeout=&quot;00:10:00&quot;
                      enabled=&quot;false&quot; /&gt;
                  &lt;security mode=&quot;None&quot;&gt;
                      &lt;transport clientCredentialType=&quot;Windows&quot; proxyCredentialType=&quot;None&quot;
                          realm=&quot;&quot; /&gt;
                      &lt;message clientCredentialType=&quot;Windows&quot; negotiateServiceCredential=&quot;true&quot;
                          establishSecurityContext=&quot;true&quot; /&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
          &lt;/wsHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
          &lt;endpoint address=&quot;http://serviceserver/MyService.svc&quot;
              binding=&quot;wsHttpBinding&quot; bindingConfiguration=&quot;WSHttpBinding_IMyService&quot;
              contract=&quot;SmsSendingService.IMyService&quot; name=&quot;WSHttpBinding_IMyService&quot; /&gt;
      &lt;/client&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  <p><strong>On the server side, my web.config file has the following <code>system.serviceModel</code> section:</strong></p>
  <pre class="lang-xml prettyprint-override"><code>&lt;system.serviceModel&gt;
      &lt;services&gt;
          &lt;service name=&quot;MyService.MyService&quot; behaviorConfiguration=&quot;MyService.MyServiceBehaviour&quot; &gt;
              &lt;endpoint address=&quot;&quot; binding=&quot;wsHttpBinding&quot; bindingConfiguration=&quot;MyService.MyServiceBinding&quot; contract=&quot;MyService.IMyService&quot;&gt;
              &lt;/endpoint&gt;
              &lt;endpoint address=&quot;mex&quot; binding=&quot;mexHttpBinding&quot; contract=&quot;IMetadataExchange&quot;/&gt;
          &lt;/service&gt;
      &lt;/services&gt;
      &lt;bindings&gt;
        &lt;wsHttpBinding&gt;
          &lt;binding name=&quot;MyService.MyServiceBinding&quot;&gt;
            &lt;security mode=&quot;None&quot;&gt;&lt;/security&gt;
          &lt;/binding&gt;
        &lt;/wsHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;behaviors&gt;
          &lt;serviceBehaviors&gt;
              &lt;behavior name=&quot;MyService.MyServiceBehaviour&quot;&gt;
                  &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt;
                  &lt;serviceMetadata httpGetEnabled=&quot;true&quot;/&gt;
                  &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
                  &lt;serviceDebug includeExceptionDetailInFaults=&quot;true&quot;/&gt;
              &lt;/behavior&gt;
          &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  <p>I've <a href="https://stackoverflow.com/questions/740039/c-wcf-wcf-service-returning-a-404-bad-request-when-sending-an-array-of-items">looked at</a> a <a href="https://stackoverflow.com/questions/323551/http-bad-request-error-when-requesting-a-wcf-service-contract">fairly large</a> <a href="http://rajaramtechtalk.wordpress.com/2008/05/29/systemservicemodelprotocolexception-the-remote-server-returned-an-unexpected-response-400-bad-request/" rel="nofollow noreferrer">number</a> of <a href="http://www.stonejunction.com/post/2008/12/01/WCF-Call-gives-400-Bad-Request-response.aspx" rel="nofollow noreferrer">answers</a> to <a href="http://www.experts-exchange.com/Programming/Languages/.NET/Web_Services/Q_24002313.html" rel="nofollow noreferrer">this question</a> with <a href="http://joewirtley.blogspot.com/2007/08/maximum-string-content-length-and.html" rel="nofollow noreferrer">no success</a>.</p>
  <p>Can anyone help me with this?</p>