使用wcf wshttpbinding的内存异常
我有一个将文件上传到服务器的应用程序。我正在使用 nettcpbinding 和 wshttpbinding。当文件大于 200 MB 时,我会遇到内存异常。解决这个问题,我看到人们推荐流式传输,当然它可以与大型文件(> 1GB)的nettcpbinding一起使用,但是当使用wshttpbinding时,该方法是什么?我应该更改为 basichttpbinding 吗?什么??谢谢。
I have an application to upload files to a server. I am using nettcpbinding and wshttpbinding. When the files is larger than 200 MB, I get a memory exception. Working around this, I have seen people recommend streaming, and of course it works with nettcpbinding for large files (>1GB), but when using wshttpbinding, what would be the approach?? Should I change to basichttpbinding?? what?? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您暴露另一个端点来上传如此大的数据。这可以有一个支持流的绑定。在我们之前的项目中,作为业务流程的一部分,我们需要将文件上传到服务器。我们最终创建了 2 个端点,一个仅用于文件上传,另一个用于所有其他业务功能。
流数据服务可以是通用服务,用于将任何数据流式传输到服务器,并且可能返回用于标识服务器上的数据的令牌。对于后续请求,可以传递该令牌以操纵服务器上的数据。
I suggest you expose another end point just to upload such large size data. This can have a binding that supports streaming. In our previous project we needed to do file uploads to server as part of business process. We ended up creating 2 endpoints one just dedicated to file upload, and another for all other business functionality.
The streaming data service can be a generic service to stream any data to the server and maybe return a token for identifying the data on server.For subsequent requests this token can be passed along to manipulate the data on server.
如果您不想(或由于合法原因而不能)更改绑定或使用流式传输,您可以做的是使用一些带有签名的方法,如下所示:
您不是发送整个文件,而是发送很少的内容数据包,并告诉数据应该放在哪里。当然,您可以添加更多数据,例如整个文件大小、文件的 CRC 来了解传输是否成功等。
If you don't want to (or cannot because of legit reasons) change the binding nor use streaming, what you can do is have some method with a signature along the lines of the following:
Instead of sending the whole file, you send little packets, and tell where the data should be placed. You can add more data, of course, like the whole filesize, CRC of the file to know if the transfer was successful, etc.