Thursday, September 29, 2011

WCF and Large Packets of data : part 2


excerpts from

To enable streaming, define the OperationContract appropriately and enable streaming at the transport level.

To stream data

  1. To stream data, the OperationContract for the service must satisfy two requirements:

    1. The parameter that holds the data to be streamed must be the only parameter in the method. For example, if the input message is the one to be streamed, the operation must have exactly one input parameter. Similarly, if the output message is to be streamed, the operation must have either exactly one output parameter or a return value.
    2. At least one of the types of the parameter and return value must be either Stream, Message, or IXmlSerializable.


[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
public interface IStreamingSample
Stream GetStream(string data);
bool UploadStream(Stream stream);
Stream EchoStream(Stream stream);
Stream GetReversedStream();


GetStream operation receives some buffered input data as a string, which is buffered, and returns a Stream, which is streamed. Conversely

UploadStream takes in a Stream (streamed) and returns a bool (buffered).

EchoStream takes and returns Stream and is an example of an operation whose input and output messages are both streamed.

GetReversedStream takes no inputs and returns a Stream(streamed).

2. Streaming must be enabled on the binding. You set a TransferMode property, which can take one of the following values:

  • Buffered,

  • Streamed, which enables streaming communication in both directions.

  • StreamedRequest, which enables streaming the request only.

  • StreamedResponse, which enables streaming the response only.

Backup Schemes




WMI – restore points

VbsEdit includes all these samples!

Download now! (32-bit version)
version 4.0   -   The evaluation version never expires