WCF/WF - Transferrin files between pcs - Asked By hema latha on 19-Jan-12 11:45 PM

Hi ..
    I want to transfer one file reside in one system to another system using wcf service. but i dont know how to do it.
 can anybody give suggetions .....
Jitendra Faye replied to hema latha on 19-Jan-12 11:54 PM
WCF streaming is helpful in all those cases when you need to move a lot of data between the client and the service in a way that keeps memory consumption under control.

Follow these links-

http://www.codeproject.com/KB/webservices/wcftransfer.aspx
http://stefanoricciardi.com/2009/08/28/file-transfer-with-wcp/

Here you will article about this.
Suchit shah replied to hema latha on 20-Jan-12 12:01 AM

try using Streaming Transfer, here's some example code showing both sending and receiving (possibly) large amounts of data using streamed transfer.

Use a binding like this, notice the MaxReceivedMessageSize and TranferMode settings.
<binding name="Streaming_Binding" maxReceivedMessageSize="67108864"  
    messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed">
</binding>

 Add some service code:
[OperationContract]
public Stream GetLargeFile()
{
    return new FileStream(path, FileMode.Open, FileAccess.Read);
}
 
[OperationContract]
public void SendLargeFile(Stream stream)
{
    // Handle stream here - e.g. save to disk  
    ProcessStream(stream);
 
    // Close the stream when done processing it
    stream.Close();
}

 And some client code:

public Stream GetLargeFile()
{
    var client = /* create proxy here */;
    try
    {
      var response = client.GetLargeFile();
 
      // All communication is now handled by the stream, 
      // thus we can close the proxy at this point
      client.Close();
 
      return response;
    }
    catch (Exception)
    {
      client.Abort();
      throw;
    }
}
 
public void SendLargeFile(string path)
{
    var client = /* create proxy here */;
    client.SendLargeFile(new FileStream(path, FileMode.Open, FileAccess.Read));
}

http://kjellsj.blogspot.com/2007/02/wcf-streaming-upload-files-over-http.html

Few more sample you will find on http://stefanoricciardi.com/2009/08/28/file-transfer-with-wcp/
http://www.codeproject.com/KB/webservices/wcftransfer.aspx
http://weblogs.asp.net/hajan/archive/2010/07/13/transferring-large-data-when-using-web-services.aspx