简体   繁体   English

文件上传,远程服务器返回错误:(413) Request Entity Too Large

[英]File Upload, The remote server returned an error: (413) Request Entity Too Large

When I upload a file via WCF services, I received the exception, "The remote server returned an error: (413) Request Entity Too Large"当我通过 WCF 服务上传文件时,收到异常“远程服务器返回错误:(413) 请求实体太大”

There are a lot of questions and answers about this exception.关于这个例外有很多问题和答案。 But, none of them is solved my problem.但是,它们都没有解决我的问题。

I'm using Windows Web Server 2008 R2, IIS 7.5.我使用的是 Windows Web Server 2008 R2、IIS 7.5。 My client and WCF applications are hosted in IIS.我的客户端和 WCF 应用程序托管在 IIS 中。 I'm using channel to call WCF service.我正在使用频道来调用 WCF 服务。

        var binding = new BasicHttpBinding();

        binding.MaxReceivedMessageSize = Int32.MaxValue;
        binding.MaxBufferPoolSize = Int32.MaxValue;
        binding.MaxBufferSize = Int32.MaxValue;
        binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
        binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
        binding.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue;
        binding.ReaderQuotas.MaxDepth = Int32.MaxValue;
        binding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;

        var address = new EndpointAddress("WCF Service URL");

        return ChannelFactory<IFileService>.CreateChannel(binding, address);

WCF configuration file like the following: WCF配置文件如下:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behavior1">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="MyProject.WCF.FileService" behaviorConfiguration="behavior1">
        <endpoint binding="basicHttpBinding" bindingName="binding1" contract="MyProject.WCF.Contracts.Service.IFileService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="binding1" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

Also, I add the client web.config file the following configurations:另外,我在客户端 web.config 文件中添加了以下配置:

<httpRuntime maxRequestLength="2097151" />

<serverRuntime uploadReadAheadSize="2147483647" />
<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483648" />
    </requestFiltering>
</security> 

I changed C:\\Windows\\System32\\inetsrv\\config\\applicationHost.config,我更改了 C:\\Windows\\System32\\inetsrv\\config\\applicationHost.config,

<location path="My Site Path" overrideMode="Allow">
    <system.webServer>
        <httpLogging dontLog="true" />
        <serverRuntime uploadReadAheadSize="2147483647" />
    </system.webServer>
</location>

But, none of them is solved my problem.但是,它们都没有解决我的问题。 There is no problem with Windows Server 2012. Probably, the problem is related to Windows Server 2008. How can upload large files with WCF in Windows Server 2008? Windows Server 2012没有问题,应该是Windows Server 2008的问题。Windows Server 2008如何用WCF上传大文件?

Thanks.谢谢。

You probably need to update the IIS request limits in the System.WebServer section, the default is 30MB.您可能需要更新 System.WebServer 部分中的 IIS 请求限制,默认值为 30MB。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="30000001" />
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

More information here:更多信息在这里:

http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits

You can do this using the Configuration Editor in IIS.您可以使用 IIS 中的配置编辑器执行此操作。

To access this, select the Website in IIS Manager, then select Configuration Editor, under the Management Section.要访问它,请在 IIS 管理器中选择网站,然后在管理部分下选择配置编辑器。 Drill down into the requestLimits section, and you can update the configuration there, as per the screenshot below.深入到 requestLimits 部分,您可以根据下面的屏幕截图更新那里的配置。 Remember to click "Apply".记得点击“应用”。 This will update the Web.Config in the root of the application.这将更新应用程序根目录中的 Web.Config。

Depending on your deployment process, this change might be lost at the next release, so it's worth considering updating your configurations in source control.根据您的部署过程,此更改可能会在下一个版本中丢失,因此值得考虑在源代码管理中更新您的配置。

在此处输入图片说明

I had to add this to web.config in the system.web section (NOTE: not system.webserver)我必须将它添加到 system.web 部分中的 web.config(注意:不是 system.webserver)

<system.web> < httpRuntime maxRequestLength="100485760" requestValidationMode="2.0" maxQueryStringLength="18192" /> </system.web> <system.web> < httpRuntime maxRequestLength="100485760" requestValidationMode="2.0" maxQueryStringLength="18192" /> </system.web>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 远程服务器返回错误:(413)请求实体太大 - The remote server returned an error: (413) Request Entity Too Large 远程服务器返回了意外的响应:(413)请求实体太大 - The remote server returned an unexpected response: (413) Request Entity Too Large Exchange Web 服务 - 请求失败。 远程服务器返回错误:(413) 请求实体太大 - Exchange Web Services - The request failed. The remote server returned an error: (413) Request Entity Too Large WCF错误:远程服务器返回错误:(413)请求实体太大 - WCF error: The remote server returned an error: (413) Request Entity Too Large 错误:远程服务器返回了意外的响应:(413)请求实体太大 - Error: the remote server returned an unexpected response: (413) Request Entity Too Large Azure云服务“远程服务器返回错误:(413)请求实体太大。” - Azure Cloud Service “The remote server returned an error: (413) Request Entity Too Large.” 远程服务器返回错误:(413)请求实体太大(尝试“每笔在地球上的解决方案”) - The remote server returned an error: (413) Request Entity Too Large (TRIED EVERY SOLUTION ON EARTH) WCF服务“远程服务器返回错误:(413)请求实体太大。” - WCF Service “The remote server returned an error: (413) Request Entity Too Large.” WCF 4.5:发生意外错误:远程服务器返回了意外响应:(413)请求实体太大 - WCF 4.5: An unexpected error occurred: The remote server returned an unexpected response: (413) Request Entity Too Large WCF 服务与 30mb 输入字符串 - 远程服务器返回错误:(413)请求实体太大 - WCF service with 30mb input string - The remote server returned an error: (413) Request Entity Too Large
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM