简体   繁体   English

在IIS7上使用WCF服务上传大文件时出现错误413

[英]Error 413 when uploading large files using WCF Service on IIS7`

I have a web application which enables users to upload files. 我有一个Web应用程序,使用户可以上传文件。 The files are then saved using a WCF service on another service. 然后使用WCF服务将文件保存在另一个服务上。 This uploading works fine until I upload a file around 4.5 MB. 在我上传大约4.5 MB的文件之前,此上传工作正常。 When I upload a file above a certain size, I get the error: 当我上传超过一定大小的文件时,出现错误:

Soap Error: 413 The server is refusing to process a request because the request entity is larger than the server is willing or able to process... Soap错误:413服务器拒绝处理请求,因为请求实体大于服务器愿意或能够处理的...

This error appears in the system event log of the server on which the WCF service is running. 该错误显示在运行WCF服务的服务器的系统事件日志中。

The solutions that I've found have told me to change the maxAllowedContentLength and uploadReadAheadSize settings in the applicationHost config file. 我找到的解决方案已告诉我更改applicationHost配置文件中的maxAllowedContentLength和uploadReadAheadSize设置。 However changing the maxAllowedContentLength to only created a different error if I set it to something really small and changing the uploadReadAheadSize value didn't have any effect on the problem. 但是,如果将maxAllowedContentLength设置为非常小的值,则将maxAllowedContentLength更改为仅会创建一个不同的错误,并且更改uploadReadAheadSize值对该问题没有任何影响。 Does anyone know what I have to change and where I have to change it? 有人知道我必须更改什么,以及在哪里更改吗? I've been looking for hours and I'm starting to get impatient :(. Thanks for the help! 我一直在找几个小时,我开始变得不耐烦:(。感谢您的帮助!

EDIT: 编辑:

Ok the web.config of the WCF Service located in the on the production system is as follows. 确定位于生产系统上的WCF服务的web.config如下。 This is the web.config located in the folder that the IIS Site of the WCF Web Services points to: 这是WCF Web服务的IIS站点指向的文件夹中的web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <handlers>
        <add name="SOAP" path="*.wsdl" verb="*" modules="IsapiModule" scriptProcessor="C:\Program Files (x86)\Common Files\MSSoap\Binaries\SOAPIS30.dll" resourceType="Unspecified" preCondition="bitness32" />
        <add name="WSDL Mapping" path="*.wsdl" verb="*" modules="IsapiModule" scriptProcessor="C:\Program Files\Common Files\MSSoap\Binaries\SOAPIS30.dll" resourceType="Unspecified" />
    </handlers>
</system.webServer>
</configuration>

The configuration on the test system is as follows: 测试系统上的配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <handlers>
        <add name="WSDL Mapping" path="*.wsdl" verb="*" modules="IsapiModule" scriptProcessor="C:\Program Files\Common Files\MSSoap\Binaries\SOAPIS30.dll" resourceType="Unspecified" />
    </handlers>
</system.webServer>
</configuration>

As you can see, there is no mention of any content length or anything in either one of the files. 如您所见,在任何一个文件中都没有提及任何内容长度或任何内容。 I have to admit, I'm pretty stumped at this point. 我必须承认,在这一点上我很沮丧。 But like I said, I'm no expert in things IIS. 但是就像我说的那样,我不是IIS方面的专家。

EDIT 2: 编辑2:

Here is the serviceModel node of my web application's web.config: 这是我的Web应用程序的web.config的serviceModel节点:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="WsJobsSoapBinding" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                    <message clientCredentialType="UserName" algorithmSuite="Default"/>
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://srvts01test:90/WsJobs.WSDL" binding="basicHttpBinding" bindingConfiguration="WsJobsSoapBinding" contract="JobsWs.WsJobsSoapPort" name="WsJobsSoapPort"/>
    </client>
</system.serviceModel>

This is the web.config of my web application that calls the WCF service and not the web.config of the WCF service itself. 这是调用WCF服务的Web应用程序的web.config,而不是WCF服务本身的web.config。 Thanks again for any help :) 再次感谢任何帮助 :)

I was also having these 413 errors in my WCF Service, which was running under .Net 4.5. 我的WCF服务(在.Net 4.5下运行)中也出现了这413个错误。

The solution was simple. 解决方案很简单。

Previously, my web.config contained this: 以前,我的web.config包含以下内容:

  <services>
    <service name="PocketCRMServices.Service1">
      <endpoint address="../Service1.svc"
        binding="webHttpBinding"
        contract="PocketCRMServices.IService1"
        behaviorConfiguration="webBehaviour" />
    </service>
  </services>

So, by default, it was already using the webHttpBinding binding. 因此,默认情况下,它已经在使用webHttpBinding绑定。

To get rid of the 413 errors, I just needed to add this straight after this section: 为了摆脱413错误,我只需要在本节之后直接添加以下内容:

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

And that's it. 就是这样。

You want to change the MaxReceivedMessageSize. 您想要更改MaxReceivedMessageSize。

I think when I did this I also had to change the MaxBufferPoolSize to the same value. 我认为当我这样做时,我还必须将MaxBufferPoolSize更改为相同的值。

You can do it via the config or via code like this. 您可以通过配置或类似的代码来实现。

            binding.MaxBufferPoolSize = 67108864;
            binding.MaxReceivedMessageSize = 67108864;

I found an article that talks about the 45KB size limit you mentioned in the chat. 我发现有一篇文章谈到了您在聊天中提到的45KB大小限制。 It includes the configuration changes that were made. 它包括所做的配置更改。

http://www.codeproject.com/Articles/166763/WCF-Streaming-Upload-Download-Files-Over-HTTP http://www.codeproject.com/Articles/166763/WCF-Streaming-Upload-Download-Files-Over-HTTP

It's possible that your test environment has these changes made so that's one thing to look for/consider. 您的测试环境可能已进行了这些更改,因此寻找/考虑是一回事。 People sometimes don't overwrite configuration files during deployment so you may have an old file there that just works. 人们有时在部署期间不会覆盖配置文件,因此您那里可能有一个旧文件才可以使用。

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

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