简体   繁体   中英

The remote server returned an error: (413) Request Entity Too Large

Please do NOT delete this message as a duplicate!!

I am writing a WCF service that allows for XML files to be uploaded so that they can be imported into the database. However I am receiving the above error when I upload a file above the 64k default.

I have read through all the questions already posted on here about this problem and implemented them but still am facing the same issue.

I have increased all the binding values in my config file (for both the client and server) to accept the maximum size of 2GB.



    <binding name="BasicHttpBinding_BailiffServices"
                     maxBufferSize="2147483647"
                     maxBufferPoolSize="2147483647"
                     maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647" 
                            maxStringContentLength="2147483647"
                            maxArrayLength="2147483647" 
                            maxBytesPerRead="2147483647"
                            maxNameTableCharCount="2147483647" />
              &ltsecurity mode="None" />

Here are the WCF services that use this binding.



    <services>
          <service name="ClientService.ClientService">
            <endpoint address="http://subversion/BusinessTier.Services.ClientService.svc"
              binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_BailiffServices"
              name="BasicHttpBinding_IClient" contract="ClientService.IClient" />
          </service>
          <service name="DebtorService.DebtorService">
            <endpoint address="http://subversion/BusinessTier.Services.DebtorService.svc"
              binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_BailiffServices"
              name="BasicHttpBinding_IDebtor" contract="DebtorService.IDebtor" />
          </service>
        </services>

I have also added settings to the config to ensure that IIS is also able to handle large files.



    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <security>
          <requestFiltering allowDoubleEscaping="true">
            <requestLimits maxAllowedContentLength="2147483647"/>
            <fileExtensions allowUnlisted="true"/>
            <verbs allowUnlisted="true"/>
          </requestFiltering>
        </security>
      </system.webServer>

As far as I can see I have amended all the necessary settings to allow my WCF service to accept large files, but none of them have so far worked.

Any suggestions would be greatly appreciated.

I found solution to avoid error like 'The remote server returned an unexpected response: (413) Request Entity Too Large.' When using basicHttpBinding in WCF Service Configuration You just need to increase the maximum message length in the Web.config.following way you can update you server web.config and client app.config file for sending large byte array via wcf.

Include following bindings and behaviors parameters in Web.config

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding maxReceivedMessageSize="2147483647" sendTimeout="00:10:00" receiveTimeout="00:10:00">
      <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"/>
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false">
  <serviceActivations>
    <add factory ="WebService.NInjectServiceHostFactory" relativeAddress="TestServic.svc" service="WebService.Services.ServiceManager"/>
  </serviceActivations>
</serviceHostingEnvironment>

I have also added binding configuration in client app.config file.

<system.serviceModel>
<bindings>
<basicHttpBinding>
  <binding name="BasicHttpBinding_IServiceManager"  maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
    <security mode="None"/>
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
  </binding>
</basicHttpBinding>
</bindings>

<client>
<endpoint address="http://localhost:49359/ServiceManager.svc"
 binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPackageManager"
 contract="PackageManager.IPackageManager" name="BasicHttpBinding_IPackageManager" />
</client>

</system.serviceModel>

this will also handle timeout error as well.

I've eventually managed to get this working after several hours of head scratching. I removed the binding name "BasicHttpBinding_BailiffServices" from both the <binding /> element and the <endpoint /> elements. I stumbled across this solution on the MSDN site. Hope this helps someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM