WCF Simplified Part 2: Message Exchange Patterns (MEPs)

There are 3 message exchange patterns in the WCF programming model:

    1. Request/Reply – A request message is sent by the client and a corresponding reply message is sent back by the server. SOAP faults that are specified in the service contract are passed to the client as a FaultException. Examples are,

    [OperationContract]
    string GetData(int value);

    [OperationContract]
    void PostData(int value);

Two things to note,

    a. The client stops processing until the return message is received. The client can choose to invoke the operation asynchronously.

    b. Even service operations that return void are request/reply but default. The client receives an empty reply message.

    2. One-way – A request message is sent by the client and there is no response message back from the service application. The client continues processing (doesn’t wait for the reply message from server). This type of MEP supports event-like behavior from a client to a service application. There can be no SOAP fault returned to indicate any errors in processing or communication. Example is,

    [OperationContract (IsOneWay=true)]
    void PostData(int value);
 

Note that the return value must be void.

3. Duplex – Both the client and the server can send messages to each other independently. This can be using either request/reply messaging,

    [ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ICallback))]
    public interface IService1 {
        [OperationContract]
        string GetData(int value);
    }

    public interface ICallback {
        [OperationContract]
        void MyCallbackFunction(string callbackValue);
    }

or using one-way messaging,

    [ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ICallback))]
    public interface IService1 {
        [OperationContract]
        string GetData(int value);
    }

    public interface ICallback {
        [OperationContract(IsOneWay = true)]
        void MyCallbackFunction(string callbackValue);
    }

We have seen the request/reply message exchange pattern in the introductory post. We’ll see the rest of the patterns in upcoming posts. 

Advertisements

About soumya chattopadhyay
I live and work in Seattle, WA. I work with Microsoft technologies, and I'm especially interested in C#.

2 Responses to WCF Simplified Part 2: Message Exchange Patterns (MEPs)

  1. Pingback: WCF Simplified Series « I.Net

  2. javaexp says:

    Nice tutorial man. I have also added some use case when each one of these soap message patterns could be used.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: