What is binding and how many types of bindings are there in WCF?

WCF Binding Types

Windows Communication Foundation (WCF) separates how the software for an application is written from how it communicates with other software. Bindings are used to specify the transport, encoding, and protocol details required for clients and services to communicate with each other. WCF uses bindings to generate the underlying wire representation of the endpoint, so most of the binding details must be agreed upon by the parties that are communicating. The easiest way to achieve this is for clients of a service to use the same binding that the endpoint for the service uses

How many types of bindings are there in WCF?

The Types of WCF Bindings:

Binding Class Name

Transport

Message Encoding

BasicHttpBinding

HTTP

Text

WSHttpBinding

HTTP

Text

WSDualHttpBinding

HTTP

Text

WSFederationHttpBinding

HTTP

Text

NetTcpBinding

TCP

Binary

NetPeerTcpBinding

P2P

Binary

NetNamedPipesBinding

Named Pipes

Binary

NetMsmqBinding

MSMQ

Binary

MsmqIntegrationBinding

MSMQ

Not Supported (uses a pre-WCF serialization format)

CustomBinding

You Decide

You Decide

 

Now let us try to understand the above WCF Binding types in detail.

BasicHttpBinding

The BasicHttpBinding uses HTTP as the transport for sending SOAP 1.1 messages. A service can use this binding to expose endpoints that conform to WS-I BP 1.1, such as those that ASMX clients consume. Similarly, a client can use the BasicHttpBinding to communicate with services exposing endpoints that conform to WS-I BP 1.1, such as ASMX Web services or services configured with the BasicHttpBinding.

Security is turned off by default, but can be added setting the mode attribute of the <security> of <basicHttpBinding> child element to a value other than None. It uses a "Text" message encoding and UTF-8 text encoding by default.

BasicHttpBinding Example:

<system.serviceModel>

  <services>

    <service

        type="Microsoft.ServiceModel.Samples.CalculatorService"

        behaviorConfiguration="CalculatorServiceBehavior">

       <endpoint address=""

             binding="basicHttpBinding"

             bindingConfiguration="Binding1"

             contract="Microsoft.ServiceModel.Samples.ICalculator" />

    </service>

  </services>

  <bindings>

     <basicHttpBinding>

        <binding name="Binding1"

               hostNameComparisonMode="StrongWildcard