On Tuesday, I left off the discussion of the messaging framework with the messaging layer, which sits beneath the hosting layer and service layer. The messaging layer is responsible for actually moving messages around. As you may have guessed from the name, the messaging layer is the part of the system that is message-oriented rather than service-oriented. The messaging layer can send and receive messages without regard to the contract or operations that your service has defined. The translation between messages and services happens inside the service layer. In WCF, the messaging layer is conceptually subdivided into a channel layer and a transport layer.
At the channel layer, messages are represented by an XML InfoSet container called Message. Channels have a top and bottom side that take an instance of Message and connect towards the application and network, respectively. When a message arrives at one side of a channel, the logic inside the channel, called the protocol, decides what gets emitted from the other side of the channel. The channel can emit 0, 1, or 37 messages (other values also permissible) in response to a single input message. Channels are selected for use with a service based on the protocol that they perform. We have channels for tasks such as security, reliable messaging, transactions, logging, message interception, and message chunking.
Collectively, all of the channels that make up an endpoint at the service layer are referred to as a channel stack. The top of the channel stack is the client or service and the bottom the channel stack is the transport layer. There are no specific responsibilities at the channel layer although a channel can modify the behavior of every service operation if it so chooses. This means that the channel layer has a lot of power but no preconceived notions about what to do with that power.
At the transport layer, messages are taken from the XML InfoSet format, converted into some byte representation, and transmitted to another party. On the other side of the transport, there is a receiver that captures the byte representation and transforms those bytes back into an XML InfoSet message. Performing the transformation between messages and bytes is handled by the message encoder while the transmission of bytes is handled by the transport channel.
Next time: Pieces of the Messaging Framework, Part 4