Note that there are some explanatory texts on larger screens.

plurals
  1. POLarge WCF web service request failing with (400) HTTP Bad Request
    text
    copied!<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> <pre><code>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. </code></pre> <p><strong>The <code>system.serviceModel</code> section of my client config file is:</strong></p> <pre><code>&lt;system.serviceModel&gt; &lt;bindings&gt; &lt;wsHttpBinding&gt; &lt;binding name="WSHttpBinding_IMyService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"&gt; &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt; &lt;reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /&gt; &lt;security mode="None"&gt; &lt;transport clientCredentialType="Windows" proxyCredentialType="None" realm="" /&gt; &lt;message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/wsHttpBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint address="http://serviceserver/MyService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService" contract="SmsSendingService.IMyService" name="WSHttpBinding_IMyService" /&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><code>&lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="MyService.MyService" behaviorConfiguration="MyService.MyServiceBehaviour" &gt; &lt;endpoint address="" binding="wsHttpBinding" bindingConfiguration="MyService.MyServiceBinding" contract="MyService.IMyService"&gt; &lt;/endpoint&gt; &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt; &lt;/service&gt; &lt;/services&gt; &lt;bindings&gt; &lt;wsHttpBinding&gt; &lt;binding name="MyService.MyServiceBinding"&gt; &lt;security mode="None"&gt;&lt;/security&gt; &lt;/binding&gt; &lt;/wsHttpBinding&gt; &lt;/bindings&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="MyService.MyServiceBehaviour"&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="true"/&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="true"/&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>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload