Message exchange pattern describes different ways to exchange messages between client and wcf service.
1. Request-Reply (default)
2. One-Way pattern
3. Duplex message exchange pattern
1. Request-Reply Message Exchange Pattern :
By default this pattern of message exchanging is followed by wcf service.
In this pattern clients sends the request message to service and wait for the response message from service.At wait time client stop processing and blocked, client continue processing after receiving response.
In this pattern client wait for completion of service call even if operation return type is void.
This pattern is supported by all wcf binding except MSMQ based binding.
In this pattern if any exception occur in service call it will immediately reported to client.
In [OperationContract] IsOneWay attribute is used to set the message exchange pattern.
If we didn't user IsOneWay attribute then default pattern is Request-Response message exchange pattern.
If IsOneWay is false : Request-Response pattern
If IsOneWay is true : One-Way pattern
Note : Duplex pattern can be implemented using both Request-response pattern and One-Way pattern
Public interface IHelloService
{
[OperationContract(IsOneWay=false)]
string sayHello(string name);
}
2. One-Way Message Exchange Pattern :
In case of one-way message exchanging pattern sender sends request message to service and its over, sender does not wait for any response from service infarct sender client does not expect any return message from it.
Set IsOneWay attribute true in OperationContract to acheive one way pattern.
Public interface IHelloService
{
[OperationContract(IsOneWay=true)]
string sayHello(string name);
}
In case of one way message exchanging pattern, If any exception occur in wcf service, it's not communicated to client means client will not be aware about service channel fault (With basicHttpBinding service channel will not be in faulted state because basicHttpBinding does not maintain session).
Note : Visit http://logicsmaze.blogspot.in/2015/05/exception-handling-in-wcf-unhandled.html for more about service channel fault
If any unhandled exception occur in service, client can't make any subsequent call with same client proxy because service will be in faulted state.
If IsOneWay is set true, you can't use output and ref parameter with operation, doing this will throw exception.
If IsOneWay is set true, Operation contract can't return anything because it's a one way communication.
One way call is not similar as asynchronous call, if server receive any one way request and server is busy to serving any other request, then call gets queued and client is unblocked.
3. Duplex message Exchange Pattern :
When client send request to service and request is time consuming like fetching report.While service is executing the request client have to wait for completion of request. But with dublex message exchange pattern, within the execution period of request service can also send messages to client like progress percentage of request or which steps are executing etc. and client can utilize this data within waiting period.
For complete code implementation of Duplex pattern please visit following post.
Duplex-Message-Exchange-Pattern-In-WCF
Related Topics :
Duplex-Message-Exchange-Pattern-In-WCF
Different-option-of-hosting-wcf-service
Binding-in-wcf-choosing-right-wcf-service
Exchanging-metadata-in-wcf
Some-interesting-facts-about-data-contract
Knowntype-attribute-in-wcf
Associating-knowntype-in-wcf
Message-contract-in-wcf
Exception-handling-in-wcf
Exception Handling in WCF - SOAP Fault in WCF
Exception Handling in WCF - Unhandled Exception in WCF
Exception Handling in WCF - Creating and Throwing Strongly Typed SOAP Fault
No comments:
Post a Comment