WCF 4.0 REST projects will return 400 Bad Request errors if the POST body is greater than 8192 characters. This is the default value of the XmlDictionaryReaderQuotas.MaxStringContentLength property. The XmlDictionaryReader class is used in the deserialization process even for JSON messages.
I saw many examples of how to solve this problem for WCF with custom bindings and endpoints, but there is no solution for REST projects for WCF 4.0 that use simplified configuration.
The regular web.config file contains a section that looks like this:
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" /> </webHttpEndpoint> </standardEndpoints> </system.serviceModel>
Firstly, the message size should be increased. To do this, add maxReceivedMessageSize to the standard Endpoint.
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="65535" />
To set MaxStringContentLength, add the following to the system.serviceModel section:
<bindings> <webHttpBinding> <binding> <readerQuotas maxStringContentLength="65535"/> </binding> </webHttpBinding> </bindings>
You need to set the length to a value suitable for your environment.
Todd
source share