System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (400) Bad Request

Recently I had a WCF service call that was returning the error System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (400) Bad Request.

Looking into this, I discivered that the messages we were sending were increasing in size.  We were using the basic http binding and it turns out the default readerQuotas were too small and were causing the"Bad Request" error.

I increased the readerQuotas to the values below and that resolved the error.

 

<basicHttpBinding>
        ...
          <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000"
            maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />

       ...

Add comment