How to Send Large File From Client To Server Using WCF?

前端 未结 3 597
不思量自难忘°
不思量自难忘° 2021-01-13 01:08

How to Send Large File From Client To Server Using WCF in C#? Below the configuration code.



        
3条回答
  •  庸人自扰
    2021-01-13 01:44

    You need to check out streaming, as Dzmitry already pointed out.

    In order to be able to send large files as a stream to your service, you'll need to:

    • create a service method that accepts a Stream as its input parameter
    • create a binding configuration (on both the server and the client) which uses transferMode=StreamedRequest
    • create a stream in your client and send it to the service method

    So first off, you need a method in your service contract:

    [ServiceContract]
    interface IYourFileService
    {
       [OperationContract]
       void UploadFile(Stream file)
    }
    

    Then you need a binding configuration:

    
      
        
      
    
    

    and a service endpoint on your service using that binding configuration:

    
      
         
      
    
    

    and then, in your client, you need to open e.g. a filestream and send that to the service method without closing it.

    Hope that helps!

    Marc

提交回复
热议问题