Understanding WCF Bindings and Channel Stack

By | June 24, 2012
In order to understand Windows Communication Foundation Bindings in details, it’s important to understand the Channel Stack as part ofWCF runtime.WCF bindingis composed of binding elements and each binding element is corresponding to a specific channel in Channel Stack. The Channel Stackcan be categorized into two major areas i.e. Protocol Channels and Transport Channels.Protocol Channels are Transaction Protocol, Reliable Messaging Protocol and Security Protocol while Transport Channels includes Message Encoding and Transport Protocol.
Transaction flow   is the optional element that controls the incoming transactions flow.Reliability is also the optional binding element specifies that reliable messaging is supported or not.

Security is another element that specifies that how security concepts like authentication, authorization, confidentiality and integrity will work.

Encoding is the required message encoding element that specifies which encoding method will be used i.e. text, binary, or MTOM.

Transport is also required binding element that specifies which transport protocol will be used i.e. TCP, NamedPipes, HTTP, HTTPS, MSMQ, or Peer-to-Peer or we can define our own custom one.

Each request coming from the client will go through Channel Stack from top to bottom and then encoded byte stream message will travels over wire. On the other end, message travel from bottom to top and reaches the service as shown in above diagram.
A complete picture of WCF runtime with Service Instance, Dispatcher and Channel Stack is as follows:

WCF is extensible, so we can defined our own bindings but there are different built-in bindings available in WCF, each designed to fulfill some specific needs.

  1. basicHttpBinding
  2. wsHttpBinding
  3. netNamedPipeBinding
  4. netTcpBinding
  5. netPeerTcpBinding

You can find difference between basicHttpBinding and wsHttpBinding in another WCF Tutorial on this blog.
For example, We should go for basicHttpBinding or wsHttpBinding, if interoperability is our concern and we need to communicate with non-WCF systems. In some case, our service can reside on a single system, In such scenario netNamedPipeBinding will be the most efficient option.
netTcpBinding or netPeerTcpBinding might be best options, if we need to communicate across multiple computers.
And if the service needs support for disconnected or queued calls, netMsmqBinding or msmqIntegrationBinding will be the candidate options.

Finally an important thing to note is, if at all possible, tries to customize an existing standard binding rather than creating a custom binding because creating new one will add the complexity to our solution.

Top 10 Interview Questions and Answers Series:

Category: Uncategorized Tags: , ,

About IMRAN ABDUL GHANI

Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net, www.topwcftutorials.net, and www.sharepointfordummies.net.

6 thoughts on “Understanding WCF Bindings and Channel Stack

  1. pramod manohar wayal

    but sir i have one ques .. if i am use netTcpBinding and my wcf service hosted on IIS7 it is possible to communicate to binary message for better performance.(IIs support for that binding ) waitting for response thanks

  2. pramod manohar wayal

    ya. it’s really good article for clearation of wcf channel stack ……..

Comments are closed.