I've implemented a small set of REST services using WCF. One of the services recieves a large amount of data. When calling it (this is when runnig it from visual studio - I haven't deployed itto a production server yet) I get the error
The remote server returned an error: (413) Request Entity Too Large.
My web config
<binding name="BasicHttpBinding_ISalesOrderDataService"
closeTimeout="00:10:00"
openTimeout="00:10:00"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true"
messageEncoding="Text">
<readerQuotas maxDepth="2000000"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
I'm afraid your client is fine but you need to check the server web.config
add value the same way you did for your client
<bindings>
<basicHttpBinding>
<binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
In addition to increasing message size and buffer size quotes, consider also increase maxItemsInObjectGraph for serializer. It can matter if your object has complex structure or array of objects inside. Our typical setting look so
<behaviors>
<endpointBehaviors>
<behavior name="GlobalEndpoint">
<dataContractSerializer maxItemsInObjectGraph="1365536" />
</behavior>
</behaviors>
<serviceBehaviors>
<behavior name="GlobalBehavior">
<dataContractSerializer maxItemsInObjectGraph="1365536" />
</behavior>
</serviceBehaviors>
And additionaly what Zwan has proposed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With