WCF Bindings


This article explains about the various types of bindings that WCF supports with examples. WCF has a couple of built in bindings which are designed to fulfill some specific need. You can also define your own custom binding in WCF to fulfill your need.

Getting Started

WCF Supports 10 types of bindigs and All built in bindings are defined in the System.ServiceModel Namespace, as i have told in introduction above you can also define your own custom binding in WCF to fulfill your need.Here is the list of 10 built in bindings in WCF which we commonly used

  1. Basic binding

    This binding is provided by the BasicHttpBinding class. It is designed to expose a WCF service as an ASMX web service, so that old clients (which are still using ASMX web service) can consume new service. By default, it uses Http protocol for transport and encodes the message in UTF - 8 text for-mat. You can also use Https with this binding. Basic binding is set as default binding in a WCF web service enabled by Silverlight and is a standard binding for communications in web service style. It does not support reliable messaging.

      <binding name="basicHttpSecure" maxBufferSize="100000"   
      <readerQuotas maxArrayLength="100000"   
        <security mode="TransportWithMessageCredential" />   

  2. Web binding

    This binding is provided by the WebHttpBinding class. It is designed to expose WCF services as Http requests by using HTTP-GET, HTTP-POST. It is used with REST based services which may give output as an XML or JSON format.

         <binding name="MobileBinding" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />  

  3. Web Service (WS) binding

    This binding is provided by the WSHttpBinding class. It is like as Basic binding and uses Http or Https protocols for transport. But this is designed to offer various WS - * specifications such as WS – Reliable Messaging, WS - Transactions, WS - Security and so on which are not supported by Basic binding.

       wsHttpBinding= basicHttpBinding + WS-* specification  
      <binding name="wsHttpBindingDefaults" allowCookies="false"   
     bypassProxyOnLocal="false" closeTimeout="00:01:00"   
     hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"   
     maxReceivedMessageSize="65536" messageEncoding="Text"   
     openTimeout="00:01:00" receiveTimeout="00:10:00" proxyAddress=""   
     sendTimeout="00:01:00" textEncoding="utf-8"   
     transactionFlow="false" useDefaultWebProxy="true" >  
      <security mode="Message">   
           <message algorithmSuite="Basic256"   
     negotiateServiceCredential="true" />   
           <transport clientCredentialType="Windows"   
     proxyCredentialType="None" realm=""/>       
  4. WS Dual binding

    This binding is provided by the WsDualHttpBinding class. It is like as wsHttpBinding except it sup-ports bi-directional communication means both clients and services can send and receive messages.

     <service name="EssentialWCF.Service1" behaviorConfiguration="EssentialWCF.Service1Behavior">  
           <add baseAddress="http://localhost/EssentialWCF"/>  
     <endpoint address="" binding="wsDualHttpBinding" contract="EssentialWCF.IService1"></endpoint>  

  5. TCP binding

    This binding is provided by the NetTcpBinding class. It uses TCP protocol for communication be-tween two machines with in intranet (means same network). It encodes the message in binary format. This is faster and more reliable binding as compared to the Http protocol bindings. It is only used when communication is WCF - to – WCF means both client and service should have WCF.

         <binding name="NetTCPBinding_IService1" sendTimeout="00:01:00">  
          <security mode="None" />  
  6. IPC binding

    This binding is provided by the NetNamedPipeBinding class. It uses named pipe for Communication between two services on the same machine. This is the most secure and fastest binding among all the bindings.

      <binding name="netPipeDefaults" closeTimeout="00:01:00"   
     maxBufferPoolSize="524288" maxBufferSize="65536"   
     maxConnections="10" maxReceivedMessageSize="65536"   
     openTimeout="00:01:00" receiveTimeout="00:10:00"   
     sendTimeout="00:01:00" transactionFlow="false"   
     transactionProtocol="OleTransactions" transferMode="Buffered">    
         <readerQuotas maxArrayLength="16384" maxBytesPerRead="4096"   
     maxDepth="32" maxNameTableCharCount="16384"   
         <security mode="Transport">       
  7. MSMQ binding

    This binding is provided by the NetMsmqBinding class. It uses MSMQ for transport and offers sup-port to disconnected message queued. It provides solutions for disconnected scenarios in which service processes the message at a different time than the client send the messages.

         <binding name=”MsmqBindingNonTransactionalNoSecurity” exactlyOnce=”false”>  
          <security mode=”None”/>  
  8. Federated WS binding

    This binding is provided by the WSFederationHttpBinding class. It is a specialized form of WS binding and provides support to federated security.

  9. Peer Network binding

    This binding is provided by the NetPeerTcpBinding class. It uses TCP protocol but uses peer net-working as transport. In this networking each machine (node) acts as a client and a server to the other nodes. This is used in the file sharing systems like torrent.

  10. MSMQ Integration binding

    This binding is provided by the MsmqIntegrationBinding class. This binding offers support to communicate with existing systems that communicate via MSMQ.

Related Articles

  1. WCF Address
  2. WCF Endpoints
  3. WCF Contracts


Above of this article we have discussed various WCF service bindings, Hope you have got about various WCF Service bindings, if this article solves your problem please give comment


No comments:

Post a Comment