Introduction: In this blog, I will describe what is streaming in WCF.

Streaming is a technique of transferring message using Streaming transfer mode. In WCF, there are two mode of transferring message which are these:

  1. Buffered transfer
  2. Streamed transfer

Buffered Transfer

Buffered transfers hold the entire message in a memory buffer until the transfer is complete. A buffered message must be completely delivered before a receiver can read it.

For buffered transfers, the native channel shape is IDuplexSessionChannel.

Streamed Transfer

Streamed transfers expose the message as a stream. The receiver starts processing the message before it is completely delivered.

For streamed transfer, the native channels are IRequestChannel and IReplyChannel.

Benefits of Streamed Transfer

  1. Improve the scalability.
  2. No need of large memory buffer.
  3. It can transfer large messages.

Restrictions to use Streaming in WCF

I/O Stream

Code:

[ServiceContract]
public interface IMyService
{
[OperationContract]
void SaveStreamData(Stream emp);

[OperationContract]
Stream GetStreamData();

}

Some Important things about streaming

  1. Stream and it's subclass can be used for streaming, but it should be serializable.

  2. Stream and MemoryStream are serializable and it will support streaming.

  3. FileStream is non serializable, and it will not support streaming.