Theoretical Introduction of Custom Binding in WCF

What is Custom Binding?

CBinding1.gif

Custom Binding provides the full control over the messaging stack for the user. We use Custom Binding, when none of the system provided binding is matching our requirement. For example let us say, your requirement is to use Http protocol to send SOAP12 message version.

Each Binding is made of different binding elements. We can construct a Custom Binding from a set of system-provided binding elements. System-provided binding elements are stacked in a specific order and we need to follow that order while creating a custom binding. Few binding elements are optional in the stack and few are required in binding elements stack.

Element Stack

CBinding2.gif
CBinding3.gif

Custom Binding is constructed using CustomBinding class. The class is defined as below

CBinding4.gif

Constructor of CustomBinding class takes different Binding elements. Binding elements get added in form of element stack described below and shown in the figure above.

Binding element stack is as below,

  • At the top is an optionalTransactionFlowBindingElement class that allows flowing transactions.
     
  • Next is an optional ReliableSessionBindingElementclass that provides a session and ordering mechanisms as defined in the WS-ReliableMessaging specification?
     
  • Next is an optional SecurityBindingElementclass that provides security features such as authorization and authentication.
     
  • Next is an optional CompositeDuplexBindingElement class that provides the ability to have two way duplex communications with a transport protocol that does not support duplex communication natively, such as HTTP
     
  • Next is an optional OneWayBindingElementclass that provides one-way communication.
     
  • Next is an optional stream security binding element which can be one of the following.

    o SslStreamSecurityBindingElement

    o WindowsStreamSecurityBindingElement

     
  • Next is a required message encoding binding element. You can use your own message encoder or one of the three message encoding bindings:

    o TextMessageEncodingBindingElement

    o BinaryMessageEncodingBindingElement

    o MtomMessageEncodingBindingElement

At the bottom is a required transport element. You can use your own transport or one of the following transport binding elements Windows Communication Foundation (WCF) provides:

  • TcpTransportBindingElement
     
  • HttpTransportBindingElement
     
  • HttpsTransportBindingElement
     
  • NamedPipeTransportBindingElement
     
  • PeerTransportBindingElement
     
  • MsmqTransportBindingElement
     
  • MsmqIntegrationBindingElement
     
  • ConnectionOrientedTransportBindingElement

There are two way to create custom binding

  1. Through configuration
  2. Through code

Creating CustomBinding through configuration

CBinding6.gif

In above custom binding, I am using all the basicHttpBinding function but have modified the message format to SOAP11.

In next article I will show you how to create custom binding. Thanks for reading. Happy Coding.

Up Next
    Ebook Download
    View all
    Learn
    View all