Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected response returned by WCF Service: (413) Request Entity Too Large

Tags:

c#

wcf

web-config

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>
like image 906
Rakin Avatar asked Sep 30 '15 12:09

Rakin


2 Answers

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>
like image 169
Zwan Avatar answered Nov 12 '22 08:11

Zwan


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

like image 3
Mimas Avatar answered Nov 12 '22 08:11

Mimas