How to handle large file uploads via WCF?

前端 未结 3 1347
暖寄归人
暖寄归人 2020-11-30 04:57

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, possibl

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 05:36

    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.

    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.

    
       
          
       
    
    

    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);
    }
    

    That should do it!

提交回复
热议问题