HTTP 400 Errors when using WCF
if you encounter the following weird errors
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:ClientPrintResult. The InnerException message was ‘There was an error deserializing the object of type System.String. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader
or
The remote server returned an unexpected response: (400) Bad Request
It usually means that you are sending more than 8192 bytes of data to the WCF service. if this is a legitimate case, you will need to update both the server’s web.config and your applications app.config.
The examples below are based on custom binding, but you can easily find the equivalent settings for the other bindings as well.
For this example, the maximum data that can be sent is 10MB (10485760). The maximum permissible value is 2147483647 (int.MaxValue = 2GB)
For web.config
modify the items in bold and blue, add in the section or properties if they do not exist, else just update the values
<binaryMessageEncoding maxReadPoolSize="10485760" maxSessionSize="10485760" maxWritePoolSize="10485760">
<readerQuotas maxDepth="32" maxStringContentLength="10485760" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport maxReceivedMessageSize="10485760" maxBufferSize="10485760" />
For app.config
modify the items in bold and blue, add in the section or properties if they do not exist, else just update the values
<binaryMessageEncoding>
<readerQuotas maxDepth="32" maxStringContentLength="10485760" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport maxReceivedMessageSize="10485760" maxBufferSize="10485760" />