Monday 19 October 2015

[SSL] WCF, The remote server returned an error: (413) Request Entity Too Large

Our file upload module was working fine with WCF when SSL was not enabled, but it gives "The remote server returned an error: (413) Request Entity Too Large." while SSL enabled. Our entire wcf configuration section is defined here where it has max maxreceivedmessagesize to 2147483647.

       

<system .servicemodel="">
    <client>
    <bindings>
      <webhttpbinding>
        <binding allowcookies="false" bypassproxyonlocal="false" closetimeout="00:02:00" hostnamecomparisonmode="StrongWildcard" maxbufferpoolsize="2147483647" maxbuffersize="2147483647" maxreceivedmessagesize="2147483647" name="RequestBinding" opentimeout="00:02:00" receivetimeout="00:02:00" sendtimeout="00:02:00" transfermode="Streamed" usedefaultwebproxy="true">
          <readerquotas maxarraylength="2147483647" maxbytesperread="2147483647" maxdepth="2147483647" maxnametablecharcount="2147483647" maxstringcontentlength="2147483647">
          
        <security mode="Transport">
          <transport clientcredentialtype="None">
        </transport></security>
        </readerquotas></binding>
      </webhttpbinding>
    </bindings>
    <services>
      <service behaviorconfiguration="ServiceBehavior" name="common.Getway">
        <endpoint address="" behaviorconfiguration="web" binding="webHttpBinding" bindingconfiguration="RequestBinding" contract="common.IGetway">
      </endpoint></service>
    </services>
    <behaviors>
      <endpointbehaviors>
        <behavior name="web">
          <webhttp>
        </webhttp></behavior>
      </endpointbehaviors>
      <servicebehaviors>
        <behavior name="ServiceBehavior">
          <servicemetadata httpgetenabled="true" httpsgetenabled="true">
          <servicedebug includeexceptiondetailinfaults="false">
          <servicethrottling maxconcurrentcalls="10000" maxconcurrentinstances="10000" maxconcurrentsessions="10000">
        </servicethrottling></servicedebug></servicemetadata></behavior>
        <behavior name="">
          <servicemetadata httpgetenabled="true" httpsgetenabled="true">
          <servicedebug includeexceptiondetailinfaults="false">
        </servicedebug></servicemetadata></behavior>
      </servicebehaviors>
    </behaviors>
    <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true">
  </servicehostingenvironment></client></system>
  <system .webserver="">
  </system>

 

Solution:
To solve this problem we need to set maxAllowedContentLength to max using RUN or we could manually add few section to applicationHost config. Here both method given with figure which will help you to solve 413 Request Entity Too Large.

Method one by Run:
       
%windir%\system32\inetsrv\appcmd set config "www.asptricks.net" -section:requestFiltering -requestLimits.maxAllowedContentLength:2147483647 /commit:apphost
   


Or Manual updates in applicationhost

Path: C:\Windows\System32\inetsrv\config\applicationHost.config,


<serverRuntime uploadReadAheadSize="2147483647" />





Tag: 413 Request Entity Too Large, WCF (413) Request Entity Too Large, SSL Request Entity Too Large.