文件上传,远程服务器返回错误:(413)请求实体过大 [英] File Upload, The remote server returned an error: (413) Request Entity Too Large

查看:3347
本文介绍了文件上传,远程服务器返回错误:(413)请求实体过大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过WCF服务上传文件时,我收到了例外,远程服务器返回错误:(413)请求实体过大

When I upload a file via WCF services, I received the exception, "The remote server returned an error: (413) Request Entity Too Large"

有很多有关此异常的问题和答案。但是,他们没有解决我的问题。

There are a lot of questions and answers about this exception. But, none of them is solved my problem.

我使用的Windows Web Server 2008 R2中,IIS 7.5。我的客户端和WCF应用程序托管在IIS。我使用的信道来调用WCF服务。

I'm using Windows Web Server 2008 R2, IIS 7.5. My client and WCF applications are hosted in IIS. I'm using channel to call WCF service.

        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配置文件,如下所示:

WCF configuration file like the following:

  <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>

另外,我想补充客户Web.config文件中的以下配置:

Also, I add the client web.config file the following configurations:

<httpRuntime maxRequestLength="2097151" />

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

我改变了C:\\ WINDOWS \\ SYSTEM32 \\ INETSRV \\设置\\的applicationHost.config,

I changed 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>

但是,他们没有解决我的问题。有与Windows Server没有问题的2012年或许,如何能在Windows Server 2008上载与WCF大文件的问题涉及到Windows Server 2008?

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?

感谢。

推荐答案

您可能需要更新的System.WebServer节IIS请求限制,则默认为30MB。

You probably need to update the IIS request limits in the System.WebServer section, the default is 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

您可以使用IIS中配置编辑器做到这一点。

You can do this using the Configuration Editor in IIS.

要访问此,请在IIS管理器的网站,然后选择配置编辑器,根据管理科。向下钻取到requestLimits部分,你可以有更新配置,如下面的屏幕截图。记住要点击应用。这将更新应用程序的根目录中的Web.Config。

To access this, select the Website in IIS Manager, then select Configuration Editor, under the Management Section. Drill down into the requestLimits section, and you can update the configuration there, as per the screenshot below. Remember to click "Apply". This will update the Web.Config in the root of the application.

根据您的部署过程,这种变化可能会在下一版本中丢失,所以这是值得考虑的源代码控制更新您的配置。

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.

这篇关于文件上传,远程服务器返回错误:(413)请求实体过大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆