Client applications and WCF
services communicate by passing XML messages. Message Exchange Patterns illustrate
how clients and services communicate by passing messages. There are three
message exchange patterns supported by WCF:
·
Request
– Reply Message Exchange Pattern
·
One –
Way
Message Exchange Pattern (also called Datagram)
·
Duplex Message
Exchange Pattern (also called Callback)
Request – Reply Message Exchange Pattern
After sending message to a WCF
service, a client application waits for
the reply in Request – Reply pattern.
This is the default and classic pattern for both WCF and Web Services. Since
the client has asked a question, and it expects an answer, it waits for the
service to send a message back containing the answer.
The Request – Reply message
exchange pattern is used when a client requests a service to perform an action,
and it needs some confirmation. Fault exception is handled in Request – Reply
pattern. The Request – Reply pattern is the most used message exchange pattern.
In Request – Reply Message
Exchange Pattern, only the client can initiate a communication with the service.
One – Way Message Exchange Pattern
The One – Way Message Exchange Pattern is also known as Datagram
or Fire
and Forget. This pattern is used when a client requests the service to take
an action but it does not need any confirmation. Thus neither the service sends
a reply message not the client waits for a reply. A client sends a message (request)
to a WCF service but the service does not send a reply message to the client.
The client does not wait for the reply
and proceeds with other processing work. Some scenario’s for one-way pattern
includes logging in and out, maintenance tasks, heads down data entry and other
repetitive tasks etc.
An implication of using one –
way pattern is that even if a method call fails due to an exception or invalid
data, the service does not notify the client. If the client needs to be
notified about the failure of the service request, then this pattern should not
be used. This pattern should be used when the client does not need to wait for
a reply from the WCF service.
In One – Way Message
Exchange Pattern, only the client can initiate a communication with the service.
Duplex Message Exchange Pattern
The Duplex Message Exchange Pattern is also known as Callback.
Both the client and the service can initiate a communication in the duplex
pattern. It can be used for transactions. The client calls the service, which after
processing the request, callbacks the client with the reply. In the meanwhile, instead
for waiting for the reply (as in Request – Reply pattern), the client proceeds
with other tasks.
This pattern should be used
when the client (after the client has called the service) expects a
notification or alert from the WCF service.
Note: The One
– Way and Duplex patterns
provides opportunities to fine-tune the performance of applications and to add
more flexibility regarding what happens after a client calls a service.
The
presence of One – Way and Duplex patterns in WCF is a major advantage of WCF over Web Services.
No comments:
Post a Comment