WCF Messaging Layer

I hope the article WCF Architecture helped you to understand how all the various layers working together. One of the layers discussed was the Messaging Layer, which defines what formats and data exchange patterns can be used when communicating with services. This article discuss what a Message is and about the  Message Structures.


A message is a packet of data containing several pieces of important information being routed from a source to a destination. It's a simple definition, so how will we relate it to WCF? Applications written using the WCF communicate through messages that are sent from a Point A to Point B (source to destination). All messages are formatted in XML.

Message Structure

WCF uses messages to pass data or exchange information from one point to another. All messages are SOAP messages. The basic structures of a SOAP message are made up of three components.

  1. SOAP Envelope

    This is the outermost component of a SOAP message. The SOAP envelope is a container for the two most important pieces of a SOAP message, the SOAP header and the SOAP body. A SOAP envelope contains several pieces of key information in the form of elements. They includes: The name of the envelope, a namespace name, an optional <header> element, a required <body> element. Check the figure below and an example.
  2. SOAP Header

    It is a collection of zero or more header blocks, i.e. a SOAP message can contain no headers or have collection of headers. So it's optional, if included then it must be the first child element of the SOAP envelop. Using a SOAP header, we can pass useful information about the services to the outer world if needed; it's just for information sharing. Any child elements of the header element are called "header blocks". This provides a mechanism for grouping logical data together.
  3. SOAP Body

    This element contains the actual SOAP message for communication with the SOAP receiver, a message can contain zero or more bodies. Any information intended to be exchanged when the message reaches the intended destination goes in the message body. In simple terms the SOAP body contains the response for the client request.



Messaging Programs

In WCF, different types of applications can send and receive messages. Those are:
  1. Clients

    In WCF a Client is the starting point or the piece that initiates the communication via the sending of a message and waits for a response.

  2. Services

    A service is a program that receives messages and performs predefined actions based on the contents of the message. Services simply
    respond to incoming messages. Services can serve multiple clients (multiple clients can call the same endpoint) and able to hold each
    session's state and keep it totally isolated from other session.

  3. Service Chains

    Service chains simply mean that a service can act like a client (reacts to an incoming message from client) and send messages to other
    services in response to an incoming message.


Messaging Patterns

Describes how programs exchange messages, using one of several patterns. There are three basic messaging patterns that programs can use to exchange messages.
  1. Simplex

    A one-way communication from Program A to Program B, without any response generated from Program B.

  2. Duplex

    A two-way communication occurs using this pattern.

  3. Request-Reply

    The Request-Reply messaging pattern doesn't allow bi-directional communication to happen freely. The client sends a response and then waits for reply. The service doesn't communicate anything until it receives a message.



These are the basics about WCF Messaging Layer, hope you enjoyed it. Please post your comments.

Up Next
    Ebook Download
    View all
    View all