04 December 2007

WCF - The remote server returned an unexpected response: (400) Bad Request.

The WCF fault "The remote server returned an unexpected response: (400) Bad Request.", might be caused by some quota or timeout on server / client side.The solution is to increase reader quota values from binding configuration on both sides:

<bindings>
<wsHttpBinding>
    <binding name="WSHttpBinding_IService" closeTimeout="00:01:00" 
    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
    maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000"
    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
    allowCookies="false">
        <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000"
        maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
        <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
        <security mode="Message">
            <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
            algorithmSuite="Default" establishSecurityContext="true" />
        </security>
    </binding>
</wsHttpBinding>
</bindings>
<services>
    <service name="MyService" behaviorConfiguration="MyServiceTypeBehaviors">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService" contract="MyIService"/>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
     </service>
</services>

13 comments:

fraxedas said...

thanks for saving me some hours of digging.

Sahil said...

Just in case you run into this - copy and paste the

bindings
wsHttpBinding
/wsHttpBinding
bindings

and

bindingConfiguration="WSHttpBinding_IResumeWebService"

into the WCF server web.config too

Alan said...

Great!
Thanks for this posting. I am implementing a WCF based solution and all was working fine until I started to process larger quantities of data. Been scratching my bald head for a day or so. All works fine now thanks.!!

Happy New Year!

Oscar said...

Thanks for the tip. Exactly what I was looking for!

Sreejith said...

I'm also facing same 404 error.
Sahil, can you please make it clear, do we need to copy and paste the

bindings
wsHttpBinding
/wsHttpBinding
bindings

and

bindingConfiguration="WSHttpBinding_IResumeWebService"

into the WCF server web.config

Anonymous said...

Thanks for this posting

azamsharp said...

I have made the changes in the client binding but still facing the same error.

azamsharp said...

I have made the changes to the client binding but I am facing the same error.

Anonymous said...

Sahil said...

Just in case you run into this - copy and paste the

bindings
wsHttpBinding
/wsHttpBinding
bindings

and

bindingConfiguration="WSHttpBinding_IResumeWebService"

into the WCF server web.config too

>>>>>>>>>

Worked for me, thanks sahil

Anonymous said...

Hey Thanks for the solution,

But just a question, we have changed the data size to 200000 everywhere, do you know specific location where we have to change or we have to change it everywhere.

Reeter said...

FYI, Bad Request can also happen if maxReceivedMessageSize on your server binding is too short, for the incoming client-to-server message size.

Thx for this article, it helped me very much.

Anonymous said...

Essa configuração deve ser colocada no arquivo de configuração do serviço ou do cliente?

Rui Inacio said...

Sim deve ser colocada no serviço e no cliente