MEP describes the way in which Client and Server communicates. It describes how client and server would be exchanging messages to each other. There are three types of message exchange patterns:
- Request- Replay (default): When client makes a request to the WCF service, it waits to get response from service till receiveTimeout expires. If client does not get any response from the service before receiveTimeout expires, TimeoutException is thrown.
- One-Way: When client makes a request to the WCF service, it does not wait for reply from the service. Service does not send any response to the sender, even if any error occurs in the communication. It does not support out or ref parameters. It does not return value to an operation. One way operation do not return values or exceptions. But while dispatching the one-way operation any error because of communication problems like host not available or address missmatch will through an exception on client side, again this depends on service instance mode and trasport session
- Duplex/Callback: Client and service can sends messages to each other by using One-way or request-reply messaging. This MEP is supported by only bidirectional-capable bindings like as WS Dual, TCP and IPC bindings.To make a duplex contract, you must also define a callback contract and assign the typeof that callback contract to the CallbackContract property of your service contract’s ServiceContract attribute.
public interface IMyDuplexServiceCallback
{
[OperationContract(IsOneWay = true)]
void Progress(string status);
}
[ServiceContract(CallbackContract = typeof(IMyDuplexServiceCallback))]
public interface IMyDuplexService
{
[OperationContract(IsOneWay = true)] //One-Way
void SaveData();
[OperationContract] //Request-Reply.
string GetData();
}
For Duplex MEP, you need to specify the one of the binding which supports bi-directional like wsDualHttpBinding as in below example:
<services>
<service name="MyWCFServices.DuplexService">
<endpoint address ="" binding="wsDualHttpBinding" con-tract="MyWCFServices.IDuplexService">
</endpoint>
You can configure MEP using IsOneWay property of OperationContract attribute as below:
[OperationContract(IsOneWay = true)]
In this above post I explained Message Exchange Pattern in WCF service. I hpe you enjoyed it so please send your feedback and queries. Thnak You.
No comments:
Post a Comment