Messaging Patterns in WCF

Messaging patterns basically describe how programs exchange messages. When a program sends a message, it must conform to one of several patterns in order for it to successfully communicate with the destination program. Likewise, the destination program must conform to the same basic patterns.
There are three basic messaging patterns that programs can use to exchange messages. Those patterns include the following:

  • Simplex :- The Simplex message pattern is simply a one-way communication from Program A to Program B. No response is generated by Program B, thus causing the one-way communication. This figure illustrates a Simplex message pattern.

    In this scenario, the client initiates communication and sends a message to the service. The service consumes the message and performs some action or behavior but does not communicate back to the client. The client in the Simplex message pattern suffers from short-term memory loss. When the client sends the message, it has no idea it sent a message because it is not expecting a response.
  • Duplex :- If the client wants a response it uses the Duplex messaging pattern. This pattern allows for both programs to communicate openly and allows information exchanges in both directions. This figure illustrates the Duplex message pattern.

    A fax machine would be an example of Duplex messaging communication. When you send a fax through the phone line, the sending machine and receiving machine make a connection and start communicating back and forth, sending information to each such as baud rate and receive status. This sending fax machine sends the scanned document to the receiving fax machine, while the receiving fax machine sends back received status information.
    The concept with this messaging pattern is that neither the sending program nor the receiving program waits for a response from the other program.
  • Request-Reply :- Unlike the Duplex messaging pattern, the Request-Reply messaging pattern doesn’t allow bi-directional communication to happen freely. In this pattern, the client sends a response and then waits for reply. The
    service doesn’t communicate anything until it receives a message. Figure 2-8 illustrates the Request-Reply message pattern.

    When you surf the web, you are witnessing the Request-Reply messaging pattern in action. When you browse to http://www.planetofcoders.com, your browser sends information to that URL requesting information from that web site. That web site then sends back the information your browser requested.
    You also see this type of messaging pattern in the form of distributed objects. WCF services have the ability to communicate using this message pattern as well as the Duplex message pattern.
Tagged . Bookmark the permalink.

Leave a Reply