Monday, August 9, 2010

Message Exchange Patterns

Message Exchange Patterns

MEPs describe the protocol of message exchanges a consumer must engage in to converse properly with the service.




1. Request/Response

This is by far the most common MEP and very little has to be done to set it up because the default value for the IsOneWay property of OperationContractAttribute is false.

Even with a void return type, if you are using Request/Response, then a response message is still going back to the consumer when the operation is called; it just would have an empty SOAP body.

2. OneWay

Sometimes, you simply want to send a message off to a service and have it trigger some sort of business logic, and you aren’t in fact interested in receiving anything back from the service. In such cases, you might want to use the OneWay MEP, that is, have the consumer simply send one-way messages into the service endpoint without any responses back from the service. This MEP is declared by setting the IsOneWay property on the OperationContractAttribute to true.

The most important one is that such an operation cannot pass any data back to the client application; it must return a void and cannot have parameters marked as out or ref.

When a OneWay operation starts running in the service, the client application has no further contact with it and will not even be aware of whether the operation was successful or not.

If the operation raises an exception that would normally generate a SOAP fault message, this SOAP fault message is simply discarded and never sent to the client.


void Cancel(string action);


The Duplex MEP is a two-way message channel whose usage might be applicable in either of these two situations.

• The consumer sends a message to the service to initiate some longer-running processing and then subsequently requires notification back from the service, confirming that the requested processing has been done.

• The consumer needs to be able to receive unsolicited messages from the service.

There are two Service contracts to consider in a Duplex MEP scenario, namely

1. the Service contract and

2. the Callback contract

This MEP is declared by associating the Callback contract with the Service contract. This association is done through the CallbackContract property of the ServiceContractAttribute that is adorning the service that needs to be capable of calling back to a consumer.

No comments: