Thursday 16 April 2015

Bindings in WCF

WCF comes with number of built-in bindings and this article describes advantages and disadvantages of each of these bindings. It will help you to choose appropriate bindings depending on your requirements and create endpoints for communicating to clients.

What is WCF Bindings?

Bindings decide how WCF service endpoint should communicate with clients. 

Each WCF service endpoint requires binding to be specified, if not set explicitly it uses default basicHttpBinding. It gives communication details and defines below things.

Protocols: specifies what type of security can be used like reliable messaging or transaction context.
Encoding: specifies type of message encoding like binary or text.
Transport: specifies communication transport to be used like HTTP or TCP.

WCF Predefined Bindings

basicHttpBinding

basicHttpBinding is best when you have traditional ASMX(Active Server Methods) web services and needs to be replace with WCF. It supports text as well as MTOM encodings and it does not support WS-* standards like WS-Addressing, WS-Security and WS-ReliableMessaging.

basicHttpBinding uses HTTP or HTTPS protocols. You can configure SSL for Transport Layer security with basicHttpBinding.

WsHttpBinding
This is secure and interoperable bindings uses SOAP over HTTP. With WsHttpBinding messages are encrypted by default and achieve message level security. It supports reliability, transactions and security over internet. It supports HTTP or HTTPS protocols and text as well as MTOM encoding.

The difference between basicHttpBinding and WsHttpBinding is WsHttpBinding does support WS-* standards like WS-Addressing, WS-Security and WS-ReliableMessaging whereas basicHttpBinding does not.

wsDualHttpBinding 
wsDualHttpBinding is best when you required bidirectional communication with client. In some scenario when client makes call to WCF service, after processing of long running request service has to call client application for example updating shipment details to client application.

It supports reliability, transactions and security over internet. It supports HTTP or HTTPS protocols and text as well as MTOM encoding. You can implement Duplex message exchange pattern with wsDualHttpBinding.

webHttpBinding 
webHttpBinding is best when you wish to implement RESTful WCF service. This is secure and interoperable binding which sends information directly over HTTP or HTTPS without creating SOAP messages. It allows HTTP request to use plain old XML (POX) style messaging which reduces the message size on wire compare to SOAP messages.

netTcpBinding 
netTcpBinding is best when WCF service and its clients are in intranet infrastructure. As it supports only TCP protocol and not HTTP so service cannot be accessed over internet.

This is secure binding is used to send binary encoded SOAP messages with in intranet computers. It supports reliability, transaction and security. If your using netTcpBinding and host WCF service in IIS, you need to make some settings on system and IIS this article will help you for required settings.

netNamedPipeBinding 
When your WCF service and its clients reside on same computer netNamedPipeBinding is the best choice and gives best performance over other bindings. This is secure bindings. Binary encoded SOAP messages are sent over named pipes.

See how to implement netNamedPipeBinding in WCF services.

netPeerTcpBinding 
netPeerTcpBinding is best when you require more security for peer to peer communication as netTcpBinding does not provide it. It is secure binding and supports TCP protocols.

WsFederationHttpBinding
It is secure and interoperable binding supports federated security. It supports HTTP and HTTPS transport protocols as well as text and MTOM encodings.

netMsmqBinding 
netMsmqBinding is best when you have to execute service operations in queued manner. Service requests are placed in queue and executed one by one. With netMsmqBinding service operations will always be one way and does not return any response to client.

This is interoperable bindings and can be used on existing MSMQ applications that use COM or Application Programing Interface(API)

In real time applications you have to use multiple bindings for one service endpoints. For example internet applications should be able to access service through HTTP request at same time the back office application should be able to access service by netTcpBinding or netNamedPipeBinding to get performance benefits.

About Author:
Dhairut Dholakia is technology lover and is important part of Systems Plus technology Think Tank. He works in systems Plus and actively contributes to technology. He can be contacted at: dhairut.d@spluspl.com

2 comments: