In this tutorial, we are going to understand Message Exchange Pattern (MEP) in WCF. In WCF Client and Server communicates and Exchange Messages using certain Pattern called as Message Exchange Pattern.
Introduction to Message Exchange Pattern:
In WCF Client and Server communicates and Exchange Messages using certain Pattern called as Message Exchange Pattern.
There are 3 types of Message Exchange Patterns (MEP)s.
Request / Response:
In Request/Response, MEP client sends a request to the service and waits for the response until the service completed its processing. If the response is not generated within the ReceivedTimeout Period a Timeout exception will be thrown. To define Request/Response Message Exchange Pattern you can set IsOneWay to false. Since this is the default Message Exchange Pattern you don’t need to set IsOneWayto false for Request/Response Patter.
One Way Message Exchange Pattern:
In some cases when we don’t want any response message back from the service for example if I need to execute a long-running task One Way MEP is suitable for such scenarios.
In One Way MEP, the client just returns the header information with an HTTP Status code 202 without a message body. One Way Pattern doesn’t have support for output Parameter, Reference Parameter and no return value
If the service is busy with the other service and client sends the request then it can keep the request in the Queue and then the client can do his other work, the client is unblocked and we can set the Queue limit of the request.
To define One Way Message Exchange Pattern we just need to set IsOneWay to true.
Duplex Message Exchange Pattern:
In duplex pattern client and server both can send messages to each other. It means Duplex is a bi-directional commination channel. This pattern implements both Request/Response and One Way.
In order to use duplex contract, weneedto define a callback contract and assign the typeof that callback contract to the CallbackContract property of your service contract’s ServiceContract.
Hope you understand MEP in WCF. Your Suggestions, Feedback and Comments are welcome.