Introduction
What is Binding? Types of
Bindings in Windows Communication Foundation.
The Binding is an attribute of an endpoint and it lets you configure transport
protocol, encoding and security requirements as shown in Figure below:
Basically, there are eight types of Bindings in
WCF. These are as following:
- BasicHttpBinding
- WSHttpBinding
- WSDualHttpBinding
- WSFederationHttpBinding
- NetTcpBinding
- NetNamedPipeBinding
- NetMsmqBinding
- NetPeerTcpBinding1
BasicHttpBinding:
- It is used for communicating with ASP.NET
Web services (ASMX)-based services that is comfortable with WS-Basic Profile
Web services.
- In this, HTTP is used as the transport .
- In this, text/XML used as the default
message encoding.
- Weak on interoperability.
- This binding does not support WS-*
functionalities like:-WS- Addressing, WS-Security, WS-ReliableMessaging.
WSHttpBinding:
- It defines a secure, reliable,
interoperable binding suitable for non-duplex service contracts.
- Supports WS-* functionality and
distributed transactions with reliable and secure sessions using SOAP
security.
- HTTP and HTTPS transport are used for
communication.
- In this, Reliable sessions are disabled by
default.
- It offers lot more functionality in the
area of interoperability.
WSDualHttpBinding:
- It support duplex service. Otherwise it is
same as WSHttpBinding.
Now a question arise, What is a Duplex service?
Ans: Duplex service is a service which uses duplex message pattern, which
allows service to communicate with client via callback.
In this Binding, reliable sessions are enabled by default. It also supports
communication via SOAP intermediaries.
WSFederationHttpBinding:
- It support federated security.
- Helps in implementing federation which
is the ability to flow and share identities across multiple enterprises.
- It supports WS-Federation protocol.
NetTcpBinding:
- It provides secure and reliable binding
environment for .Net to .Net cross machine communication.
- It creates communication stack using WS-ReliableMessaging
protocol for reliability,TCP for message delivery and windows security for
message and authentication at run time.
- It uses TCP protocol and provides support
for security, transaction and reliability.
NetPeerTcpBinding:
- It Provides full support for SOAP
security,transaction and reliability.
- TCP used for communication.
- Provides secure binding for peer- to- peer
environment and network.
NetMsmqBinding:
- Used for enabling disconnected
operations,overload leveling etc.
- MSMQ is used for queuing.
- It provides secure and reliable queued
communication for cross-machine environment.
NetNamedPipeBinding:
- It uses NamedPipe protocol and provides
full support for SOAP security.
- This binding also provides secure and
reliable binding environment for on-machine process communication.
- It creates communication stack with WS-ReliableMessaging
for reliability,named piped for message delivery and binary encoding.
Process to
set up BasicHttpBinding:
Let us examine how to setup binding for an endpoint in the web.config file.
Step 1: Choose basicHttpBinding as a value in the binding attribute of an
endpoint.
<endpoint
address="http://localhost:8731/EmployeeWCFService.ServiceImplementation.Manager/"
binding="basicHttpBinding"
bindingConfiguration="basicBinding"
contract="
EmployeeWCFService.ServiceContract.IEmployee">
Step 2: This step is optional and is only required if the binding's
default properties need to be modified, as shown in the example below. In this
case, name the binding same as bindingConfiguration attribute in the endpoint
section.
<bindings>|
<basicHttpBinding>
<binding
name="basicBinding"
textEncoding="utf-8"
openTimeout="00:03:00"
closeTimeout="00:03:00"
/>
</basicHttpBinding>
</bindings>