wcf

Error message "WCF Service Error 413 Entity Too Large"


I need some insight on where to look further related to a WCF error I am getting about the Request Entity Too Large (Error 413).

Pretty much, the service is a simple [OperationContract] accepting a string as a parameter.

<IService.cs>
[OperationContract]
string UploadReportText(string ReportText);


<Service.cs>
public string UploadReportText(string ReportText)
{
  // Code to process data passed.
}

I've already set the web configuration for the service as follows:

<bindings>
 <webHttpBinding>
    <binding maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647"
                    maxStringContentLength="2147483647"
                    maxArrayLength="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
   </binding>
 </webHttpBinding>
</bindings>

Although I believe the uploadReadAhead value in IIS needs not be touched (as I am not using SSL), I still modified it to have a value of 2147483647.

Tracing one of the applications that call the service in Chrome, I can see that the data 'Content-Length' is 169786.

I am really stumped where to look further related to this.

If I set the string data being passed to the service to a smaller length, I am not getting an error. Most of the search I did related to this all points to the maxReceivedMessageSize needs to be adjusted to the maximum possible value, but setting it in the web configuration seems to not have any effect.

I enabled logging, and I got this message:

Exception details: System.ServiceModel.ProtocolException: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.


Solution

  • First of all: on your server side, you define the binding configuration with larger message size, but you don't reference it from your endpoint.

      <service behaviorConfiguration="WCFReferrals.Service1Behavior"
                 name="WCFReferrals.Referrals">
           <endpoint 
                 address="" 
                 binding="wsHttpBinding" 
                 bindingConfiguration="LargeSizeMessages"  <== you need to reference the binding config (by specifying its name
                contract="WCFReferrals.IReferrals">
            </endpoint>
            .....
          </service>
          ....
          <binding name="LargeSizeMessages"   <== give it a meaningful name
               maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
               <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                   maxArrayLength="2147483647" maxBytesPerRead="4096" 
                   maxNameTableCharCount="16384" />
          </binding>
    

    Source

    Refer this too