How do I upload large (> 25MB) files to a web serv

2019-01-16 07:19发布

I have a web service that takes a byte[] and saves it.

This works fine for "small" files, but once I hit a certain size the web service fails and returns "The request failed with HTTP status 404: Not Found."

From what I've seen this appears to be an IIS setting that limits the size of a file that can be posted (to prevent Denial of Service attacks). I've tried to increase that setting, but I am having trouble determining what setting and where/how one would set it. I am using IIS7 and the webservice is done in .net (asmx).

In the web.config of the web service I have added the following (which seemed to increase the size of file that can be accepted, but not all the way to this setting size)

  <system.web>
     <httpRuntime executionTimeout="999999" maxRequestLength="2097151" />
     ...
  </system.web>

Any suggestions on where (and how) to increase the size of file that the web service would be greatly appreciated.

8条回答
手持菜刀,她持情操
2楼-- · 2019-01-16 08:15

You should keep in mind that web services aren't primarily designed as file transfer mechanisms. Any purpose-designed file transfer protocol will likely do a better job than a web service. For instance, such protocols are more likely to deal with error recovery, partial uploads, etc.

However, if you're going to use web services for this purpose in .NET, you should use WCF, if at all possible. Among other benefits, WCF handles streaming, and will therefore be a lot more efficient in terms of memory usage. I'm concerned that if you follow the two (accurate) suggestions above, your next result will be "out of memory or resources" exceptions, as the old ASMX technology tries to load your entire 25MB file into memory at once. In fact, it may have several copies in memory at the same time!

查看更多
做自己的国王
3楼-- · 2019-01-16 08:16

In addition to the httpRuntime/maxRequestLength mentioned in the question, it looks like there is an additional item that can be added to the web service's web.config file to permit large file transfers.

  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2000000000" />
      </requestFiltering>
    </security>
  </system.webServer>

This appears to enable larger files to be uploaded via web services.

查看更多
登录 后发表回答