WCF Simplified Part 2: Message Exchange Patterns (MEPs)
May 25, 2010 1 Comment
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.
Pingback: WCF Simplified Series « I.Net