Prerequisites: Understanding WCF in depth - Part 1
From the previous post, we understood the 2 core components of WCF, viz. Channel Stack and Service Framework.
In this post, we will look at the internal behavior of Channel stack and Service Framework and its components.
First, let us look at the internal components using the Message Flow Diagram which is below:
Message Flow
Service Layer: From the above, the Service Layer or the Service Framework makes the task easier for the developer. Ideally, a developer needs to write a Message
class to be passed into the Channel Stack and this again is a tedious task. The Service F/W gives the leverage for the developers to define & decorate service, message and data contracts, thus internally it creates a Message
instance for you. So simple, isn’t it.
Proxy & Dispatcher: It’s the responsibility of the proxy component on the client side and dispatcher component on the service side to mediate and translate between the service and the message layers. In short, the proxy component transforms .NET method calls into Message
objects, whereas the dispatcher component turns WCF Messages into .NET method calls.
The service looks for the methods exposed by the proxy and uses this to pass a message to the method.
Channel Stack: A valid message instance comes to the Channel stack asking it to perform some operation and transport it then as raw bytes. The Message
passes through each Protocol channel allowing them to operate on the message. The Message
then arrives to the Encoder, Encoder converts the Message
into raw bytes which are ready for transporting then.
The same process occurs in the server side where in the incoming raw bytes of message are then decoded and passed through various protocol channel to produce a valid Message
which is then fed to the dispatcher. Dispatcher finds target service endpoint using the destination address and Action property contained in the Message, deserializes the content of the WCF Message into objects. Then the method is invoked.
As of now, we have studied the flow and what happens in the channel stack, we will in brief look at the Binding Elements for the layers above:
Protocol Binding Elements |
Protocol | Class | Element |
Transaction Flow | TransactionFlowBindingElement | <transactionFlow/> |
Reliable Messaging | ReliableSessionBindingElement | <reliableSession/> |
Security | SecurityBindingElement | <security/> |
Message Encoding Binding Elements |
Message Encoding | Class | Element |
Text | TextMessageEncodingBindingElement | <textMessageEncoding/> |
MTOM | MtomMessageEncodingBindingElement | <mtomMessageEncoding/> |
Binary | BinaryMessageEncodingBindingElement | <binaryMessageEncoding/> |
Transport Security Binding Elements |
Transport Security | Class | Element |
Windows | WindowsStreamSecurityBindingElement | <windowsStreamSecurity/> |
SSL | SslStreamSecurityBindingElement | <sslStreamSecurity/> |
Transport Binding Elements |
Transport | Class | Element |
HTTP | HttpTransportBindingElement | <httpTransport/> |
HTTPS | HttpsTransportBindingElement | <httpsTransport/> |
TCP | TcpTransportBindingElement | <tcpTransport/> |
Named pipes | NamedPipeTransportBindingElement | <namedPipeTransport/> |
MSMQ | MsmqTransportBindingElement | <msmqTransport/> |
MSMQ | MsmqIntegrationBindingElement | <msmqIntegration/> |
P2P | PeerTransportBindingElement | <peerTransport/> |
In the next post, we will see why endpoint is needed and its components.