How to choose a WCF binding ?

facebooktwittergoogle_plusredditpinterestlinkedinmail

How to choose a WCF binding

In this article, I’m going to explain how to choose a binding for your Windows Communication Foundation (WCF) service. Before going to that, we need to know what is WCF binding.

What is WCF binding ?

Bindings are transport mechanism for the messages. Binding defines how the WCF service going to communicate with the other end points. There are lots of bindings available in WCF but most of the cases we will use only 4 or 5 bindings.

Http bindings

This binding can outside the firewall through port 80. The primary Http bindings are basicHttpBinding and wsHttpBinding . These bindings are not secure by default, However, we can make it secure and encrypted using certificates. These two binding would not support duplex communication. A duplex contract allows clients and servers to communicate with each other independently so that either can initiate calls to the other. Duplex communication can be achieved using wsDualHttpBinding . You can use WebHttpBinding to have REST endpoints in your WCF application to expose simple public service calls.

TCP bindings

TCP binding typically for the communication inside the firewall. netTCPBinding is used for communicating with WCF client in an intranet environment and provides transport security and Windows authentication by default. TCP binding is fast compared to Http bindings.

IPC bindings

Inter-Process Communication (IPC) is the fastest and most secure communication but that are limited to single machine.This binding is provided by the NetNamedPipeBinding class.

UDP bindings

These bindings are similar to TCP binding but faster than TCP. UDP bindings are Non-reliable and limited to subnet without bridging. This binding commonly used to send small messages to a large number of recipients at the same time without the need to establish a point to point connections.

MSMQ bindings

This binding provides disconnected communication between the client and the server . The netMsmqBinding is the queued binding WCF provides for two WCF endpoints to communicate using MSMQ.

How To Choose A WCF Binding ?

In the following follow diagram explains how to choose a WCF binding based on your requirement.

How To Choose A WCF Binding

The first criteria is based on the firewall. If you want to communicate outside the firewall then mainly we have 3 options. Choose WebHttpBinding if you want a REST service. BasicHttpBinding is suitable if you have legacy systems to communicate with the WCF else choose WsHttpbinding.

If your client and server in thesame machine then choose NetNamedPipeBinding . If your clients and WCF service are inside your firewall choose NetTcpBinding, its provides reliability. If you do not want message reliability then choose NetUdpbinding. If the communication between client and server is in disconnected mode inside firewall then choose NetMsmqBinding.

The following two tabs change content below.

Tom Mohan

Tom Mohan is a technologist who loves to code and build. He enjoys working on Microsoft Technologies. Tom specializes in ASP.NET MVC, Web API , Azure, C# ,WPF, SQL etc and holds a Bachelor engineering degree in Computer Science. Certification : MCSD , MCTS