Applications written using Windows Communication foundation communicate through messages. WCF uses SOAP messages, formatted in XML as SOAP messages.
Lets discuss each of the section in detail
SOAP Envelope is outer most section of WCF message. It acts as a container for WCF header and body. A SOAP envelope contains several pieces of key information in the form of elements. They include the following:
- The name of envelope
- Namespace name : The namespace name must be “http://www.w3.org/2003/05/soap-envelope”.
An optional <header> element: SOAP header is a collection of one or more than one header block. A SOAP message can contain zero or more than one header block. If a header is included, it must be the first child element of the envelope element. Header is good place to put optional information related to message. Any child element of header element is called “Header Blocks”. The following code sample illustrates the basic format for including a message header:
<env:Envelope xmlns:s=”http://www.w3.org/2003/05/soap-envelope” xmlns:a=”http://schemas.xmlsoap.org/ws/2004/08/addressing”>
- A required body element. : The SOAP body is a collection of data items to be used at a specific target (SOAP receiver). Like the SOAP header, a message can contain zero or more bodies.
WCF Messaging Programs
In WCF ,following type of applications can send and receive messages
- Client: Client is a program that initiates a communication via sending a message
- Service: Service is program that respond to a message. Service perform predefined activities once it receives a message. A service never initiates a communication. While processing request , if the service call some other services than this concept is called “Service chain”. Here the service is acting as client and service has initiated the communication in response to incoming message.
Messaging patterns, basically describe how programs should exchange messages. 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. Simplex messaging 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: In duplex pattern client and service programs communicate openly and exchange information in both directions.
- Request-Reply: 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.