如何通过WCF处理大文件上传? [英] How to handle large file uploads via WCF?

查看:324
本文介绍了如何通过WCF处理大文件上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待到使用WCF的项目,该项目将需要为人们大文件(64MB-1GB)上传到我的服务器的能力。我将如何与WCF处理这种情况,可能与恢复上传的能力。

I am looking into using WCF for a project which would require the ability for people to upload large files (64MB-1GB) to my server. How would I handle this with WCF, possibly with the ability to resume uploads.

为了处理一个更大的客户群,我想通过WCF来测试JSON。这将如何影响文件上传?能不能从JSON完成,否则他们将需要切换到休息上传部分?

In order to handle a larger client base, I wanted to test out JSON via WCF. How would this affect the file upload? Can it be done from JSON, or would they need to switch to REST for the upload portion?

推荐答案

如果您要上传大文件,你一定要考虑的 WCF串流模式

If you want to upload large files, you'll definitely need to look into WCF Streaming Mode.

基本上,你可以在你的绑定将传输模式更改;默认情况下,它的缓冲,即需要在发送端进行缓冲,系列化,然后作为一个整体传输的整个消息。

Basically, you can change the transfer mode on your binding; by default, it's buffered, i.e. the whole message needs to be buffered on the sender, serialized, and then transmitted as a whole.

通过流媒体,可以定义两种单向流(上载只,仅用于下载)或双向流。这是通过设置您的结合 StreamedRequest StreamedResponse ,或只是简单的transferMode完成

With Streaming, you can define either one-way streaming (for uploads only, for downloads only) or bidirectional streaming. This is done by setting the transferMode of your binding to StreamedRequest, StreamedResponse, or just plain Streamed.

<bindings>
   <basicHttpBinding>
      <binding name="HttpStreaming" 
               maxReceivedMessageSize="2000000"
               transferMode="StreamedRequest"/>
   </basicHttpBinding>
</bindings>

然后,你需要有这两种接收类型的参数(上载),或返回类型的值流服务合同(对于下载)。

Then you need to have a service contract which either receives a parameter of type Stream (for uploads), or returns a value of type Stream (for downloads).

[ServiceContract]
public interface IFileUpload
{
    [OperationContract]
    bool UploadFile(Stream stream);
}

这应该这样做!

这篇关于如何通过WCF处理大文件上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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