Sending Big Files with WCF

Posted by Sean Feldman on ASP.net Weblogs See other posts from ASP.net Weblogs or by Sean Feldman
Published on Sun, 30 May 2010 23:36:00 GMT Indexed on 2010/05/30 23:43 UTC
Read the original article Hit count: 555

Filed under:
|

I had to look into a project that submits large files to WCF service. Implementation is based on data chunking. This is a good approach when your client and server are not both based on WCF, bud different technologies.

The problem with something like this is that chunking (either you wish it or not) complicates the overall solution. Alternative would be streaming. In WCF to WCF scenario, this is a piece of cake. When client is Java, it becomes a bit more challenging (has anyone implemented Java client streaming data to WCF service?).

What I really liked about .NET implementation with WCF, is that sending header info along with stream was dead simple, and from the developer point of view looked like it’s all a part of the DTO passed into the service.

[ServiceContract]
public interface IFileUpload
{
  [OperationContract]
  void UploadFile(SendFileMessage message);
}

Where SendFileMessage is

[MessageContract]
public class SendFileMessage
{
  [MessageBodyMember(Order = 1)]
  public Stream FileData;

  [MessageHeader(MustUnderstand = true)]
  public FileTransferInfo FileTransferInfo;
}

© ASP.net Weblogs or respective owner

Related posts about .NET

Related posts about wcf