WCF Bindings, What is Binding, different types of Bindings

 

There are many ways to communicate with any service and there are many possible protocols to communicate with given service such as HTTP (or HTTPS), TCP, IPC, and MSMQ. We can use any encoding option while communicate with the service. Messages can follow a synchronous request-reply or asynchronous fire-and-forget pattern, messages can be bidirectional, and messages can be delivered immediately or queued, and the queues can be durable or volatile between service and client. Based on all these possible communication and interaction options, we can communicate with the given service in different ways. 

 

In WCF, binding is defined as how to communicate with the service. Binding includes transport schema, encoding options, message delivery mechanism…etc. A binding is merely a consistent, canned set of choices regarding the transport protocol, message encoding, communication pattern, reliability, security, transaction propagation, and interoperability.  

 

In WCF we have several bindings; we just need to select correct binding based on our requirements. The service publishes its choice of binding in its metadata, enabling clients to query for the type and specific properties of the binding. This is required because client must use the same binding values as mentioned in the service. That means while selecting any binding we have to consider both client and server. We have to select particular binding from several options which is suitable for both service and client.

 

You can define multiple bindings for single WCF service based on our requirement. You can select binding from available WCF binding or you can define custom binding based on our requirement.

 

There are different predefined bindings available in WCF. Those are Basic binding, TCP binding, IPC binding, Web Service (WS) binding and MSMQ binding.

We will discuss each binding below in-detail. 

 

BasicHttpBinding or Basic binding:

 

BasicHttpBinding is the .Net class that supports Basic binding. BasicHttpBinding is designed to expose a WCF service as a legacy ASMX web service, because of this Old clients can work with new services. By using this binding WCF clients can easily work with old ASMX web services. This binding supports http, https protocols and text, MTOM encoding mechanisms.

 

NetTcpBinding or TCP binding:

 

NetTcpBinding is the .Net class that supports TCP binding. We can use the NetTcpBinding binding for WCF-to-WCF communication. That means if the client and service are using WCF we can NetTcpBinding binding. It supports various features like reliability, transactions and security. It supports TCP protocol and Binary encoding mechanism. 

 

NetNamedPipeBinding or IPC binding:

 

NetNamedPipeBinding is the .Net class that supports IPC binding. NetNamedPipeBinding or IPC binding uses named pipes as transport within the machine. That means if the client and service are in same machine, we can use this binding for variety of features similar to the TCP binding. IPC binding is the most performant binding because it is lighter than TCP protocol.

 

WSHttpBinding or Web Service binding: 

 

WSHttpBinding is the .Net class that supports Web Service binding. WSHttpBinding or WS binding is used for any client that supports the WS standards. This binding supports http, https protocols and text, MTOM encoding mechanisms. It also provides variety of features such as reliability, transactions, and security.

 

NetMsmqBinding or MSMQ binding: 

 

NetMsmqBinding is the .Net class that supports MSMQ binding. NetMsmqBinding uses MSMQ(Microsoft Message Queue) for transport and offers support for disconnected queued calls. NetMsmqBinding supports MSMQ protocol and binary encoding mechanism.