Message Layer in WCF ( How message passes from clients to service and vice versa )


In my previous article ( ABC of WCF ) I have given some brief idea about the basic concept of WCF.
Here we will see how the message is passed between the client and the service.

Different modes of message transmission and how it works.

Behind The Scene

While, we are talking about WCF, we should keep in mind that there is two separate parts in WCF programing. One is client and another is service. And in order to access the service the client needs to send some message to the service with some argument in a certain format, that is described in the
binding section of the service.
This messaging layer defines in what format and patterns the data is exchanged between client and service.

Client - Service Communication


A message is a packet of data, that is transmitted from the client to the service and vice versa in a secure manner. The messages are formatted in XML.

WCF meassages are generally SOAP( simple object access protocol ) messages. Here I am giving you  brief idea about the SOAP messages.

 The SOAP message contains three parts such as

  • SOAP Envelope
                 The is the outermost part of the SOAP message. 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.
  • 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
  • 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.


<?xml version="1.0"?>


    This is just for Information to outer world



   Message goes here


In WCF there the messages can be sent from a client to a service, from a service to a client and from a service to a service.

Messaging Patterns

  • Simplex
              One way communication between the client and the service, here the message is being sent from the client to the service without any response from the latter.

Simplex Messaging
  •  Duplex
            Here two way communication is occurred between the service and the client. The client requests some task to the service and the service responds back to the client with the result.

Duplex messaging

  •  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.

Request Reply Messaging

That's all about the messaging in WCF service, hope you enjoyed this article.

Happy Coding...

Previous Next

No comments:

Post a Comment