简体   繁体   English

使用 WCF 服务传输大文件 - 检索错误 413

[英]Transfer large files using WCF Service - Retrieve Error 413

I know this topic has been discused multiple times already, but unfortunately non of the provided solutions workd for me.我知道这个话题已经被讨论过多次,但不幸的是,没有提供的解决方案对我有用。 I try to transfer large files (up to 1.5 GB) from a client console application to a WCF service.我尝试将大文件(最多 1.5 GB)从客户端控制台应用程序传输到 WCF 服务。 But I always get an HTTP error The remote server returned an unexpected response: (413) Request Entity Too Large.但我总是收到 HTTP 错误远程服务器返回了意外响应:(413) 请求实体太大。 while transmitting the file content.在传输文件内容时。

All information I found in the internet where about adding maxContentLength and similar configuration to web.config file.我在互联网上找到的关于将 maxContentLength 和类似配置添加到 web.config 文件的所有信息。 But I assume I entered them at a wrong part from the web.config or so.但我假设我在 web.config 左右的错误部分输入了它们。

Edit 26.02.2020 18:35 (updated due to hints and new tests)编辑 26.02.2020 18:35(由于提示和新测试而更新)

Based on the tipps from above I added some entries to config files and did some more tests.基于上面的提示,我在配置文件中添加了一些条目并进行了更多测试。 In the mean time I found out a few things:与此同时,我发现了一些事情:

  • The number in web.config define the size in bit not in bytes as I read on severall pages当我在几个页面上阅读时,web.config 中的数字以位为单位而不是以字节为单位定义大小
  • The number must be a valid int32 - so the maximum value is 2147483647该数字必须是有效的int32 - 所以最大值是2147483647
  • 2147483647 bit are around 256 MByte - so it's understandable, that my testfile with around 400MB caused a problem 2147483647 位大约为256 MB - 所以这是可以理解的,我的大约 400MB 的测试文件引起了问题

Overall, if it's not possible to transfer the large files - at least 20-30 MB should be possible.总的来说,如果无法传输大文件 - 至少20-30 MB应该是可能的。 For larger files I will find an other solution then.对于较大的文件,我会找到其他解决方案。

To do easier tests I just created a new empty WCF service and a console application to test it.为了进行更简单的测试,我刚刚创建了一个新的空 WCF 服务和一个控制台应用程序来测试它。

You can find the complete sourcecode on Google Drive .您可以在Google Drive上找到完整的源代码。 I included a 22MB test image as well, which doesn't work to transfer.我还包含了一个 22MB 的测试图像,但无法传输。

Different to my first problem, I now get a 404 error instead of a 413. So somehow the IIS returns a 404 when the request is not matchable to a service instead of the previous 413. A pretty strange behaviour for me.与我的第一个问题不同,我现在得到 404 错误而不是 413。所以当请求与服务不匹配而不是以前的 413 时,IIS 以某种方式返回 404。对我来说,这是一个非常奇怪的行为。

The web.config and the app.config looks still the same as before (beside there is no entity framework stuff in). web.config 和 app.config 看起来仍然和以前一样(除了没有实体框架的东西)。

Server web.config服务器 web.config

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="mybinding"  maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="None"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <protocolMapping>
      <add binding="basicHttpBinding" scheme="http" bindingConfiguration="mybinding" />
    </protocolMapping>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

Client app.config客户端 app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="mybinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:53042/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="mybinding" contract="ServiceReference1.IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>

As I'm not a pro regarding web.config configuration, I assume, I just added the configuration in a wrong section of the XML.由于我不是 web.config 配置方面的专家,我假设我只是在 XML 的错误部分添加了配置。 Can anybody provide me some help, how my web.config need to look like, that I can transfer larger files.任何人都可以为我提供一些帮助,我的 web.config 需要如何,我可以传输更大的文件。

Thanks in advance提前致谢

Regards Markus问候马库斯

The service now publishes the endpoint using ProtocolMapping section, I suggest you name the binding and apply the configuration to the properties below.该服务现在使用ProtocolMapping部分发布端点,我建议您命名绑定并将配置应用于下面的属性。

    <bindings>
      <basicHttpBinding>
        <binding name="mybinding" ... >
        ...
        </binding>
      </basicHttpBinding>
    </bindings>
<protocolMapping>
      <add binding="basicHttpBinding" scheme="http" bindingConfiguration="mybinding"/>
</protocolMapping>

If it doesn't work, we could publish the service by using the following style.如果它不起作用,我们可以使用以下样式发布服务。

<system.serviceModel>
    <services>
      <service name="WcfService1.Service1">
        <endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" bindingConfiguration="mybinding"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
      </service>
</services>

Feel free to let me know if the problem still exists.如果问题仍然存在,请随时告诉我。

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

相关问题 如何通过使用缓冲传输模式将大文件从Windows服务发送到WCF服务 - how to send large files to wcf service from windows service by using Buffered transfer mode (413)使用WCF请求实体太大错误 - (413) Request Entity Too Large error with WCF WCF中的请求实体太大错误(413) - Request entity too large error(413) in WCF 如何为413请求实体错误配置WCF服务应用程序 - How to Configure WCF Service Application for 413 Request Entity Too Large Error WCF服务“远程服务器返回错误:(413)请求实体太大。” - WCF Service “The remote server returned an error: (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 传递大字节时,WCF服务错误413“实体太大” [] - WCF Service Error 413 “Entity Too Large” when pass big byte[] WCF-大文件上传-(413)请求实体太大 - WCF - large files upload - (413) Request Entity Too Large WCF服务返回意外响应:(413)请求实体太大 - Unexpected response returned by WCF Service: (413) Request Entity Too Large 与WCF服务通话时,“ 413请求实体太大” - Getting “413 Request Entity Too Large” when talking to WCF service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM