Message is the key in WCF. Without messages we do not have
anything! As I stated in the first part, services, clients and intermediaries communicate
with each other via messages. They send and receive messages in order to do
First, it is better to give a background about message
structure in WCF. Each message in WCF is an XML document (especially SOAP
Envelope) that consists of two main parts: headers and body.
Each message may contain one or more headers, but only has
one body. Headers are some means that infrastructures or developers consume
and they are mainly used to represent some information about the message
itself. The body is what we (developers) should care about because most of our
codes will be applied to the body. The body is where our data is located.
Based on our needs in WCF we deal with messages in one of following
Simplex: This is a one way messaging pattern.
Request-Reply: This is a two way asynchronous messaging pattern.
Duplex: This is a two way synchronous pattern.
Let us take a look at these three patterns in more detail.
In simplex pattern, which is a one way asynchronous pattern,
you send a message from client to service and nothing more (Figure 1).
In the request-reply pattern the client sends a request to the
service and waits until it returns a reply back. Nothing can happen in this
between service and client. Request-reply is a common pattern for internet
users and everyday you deal with this pattern on internet.
In the duplex pattern the client and service can communicate
with each other regardless of anything that is going on between them so a
client can send a message to the service and the service can send a message to
the client. Here, neither the client nor service needs to wait.