0 votes
in Education by (557k points)

What is Duplex in WCF? Explain also Message Exchange Pattern?

1 Answer

0 votes
by (557k points)

Duplex

Duplex is a Two-Way Communication Process. In which, a consumer send a message to the service and the service sends a notification that the request processing has been done. It is just like that we send some command about the printing of some papers to the Printer machine. The printer machine start communication by making the connection with our machine, and start printing the paper.

  1. Duplex service allows calling back some operation (function) on the client.
  2. Duplex service also knows as Call Backs.
  3. All Binding does not support duplex service.
  4. Duplex communication is not standard. They are absolute Microsoft feature.
  5. wsDualHttpBinding supports duplex communication over HTTP binding.
  6. Duplex communication is possible over netTcpBinding and netNamedPipeBinding
  1. [ServiceContract(CallbackContract = typeof (DuplexServiceCallback))]  
  2. public interface IMyService  
  3. {  
  4.     [OperationContract(IsOneWay = true)] //one-way message   
  5.     void AddName(string name);  
  6.     [OperationContract] //request-response message   
  7.     string GetName(string name);  
  8. }  

Message Exchange Patterns in WCF:

The Message Exchange Pattern (MEP) provides a way of communication between client and server. MEP is a beauty of WCF. A services do some task depend on us or send a response to our request. The communication between client and server are done in form of messages. When we send a message as request and get a message as response from the service. The WCF Services support three types of Message Exchange Pattern:

  • Request-Response
  • One-Way
  • Duplex

Why we need the Message Exchange Pattern:

  1. When we want the calling of the function to not take more time.
  2. We just want to call the function and not want wait for the response.
  3. When we want that function call is not blocking and at the same time we want something out of the function (response) for our application.
  4. When we want a two-way communication mechanism.
...