Theoretical introduction of Custom Binding in WCF

What is Custom Binding?
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

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

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 optional TransactionFlowBindingElement class that allows flowing transactions.
  • Next is an optional ReliableSessionBindingElement class that provides a session and ordering mechanisms as defined in the WS-Reliable Messaging specification?
  • Next is an optional SecurityBindingElement class 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 OneWayBindingElement class that provides one-way communication.
  • Next is an optional stream security binding element which can be one of the following.
    • SslStreamSecurityBindingElement
    • WindowsStreamSecurityBindingElement


  • Next is a required message encoding binding element. You can use your own message encoder or one of the three message encoding bindings:
    • TextMessageEncodingBindingElement
    • BinaryMessageEncodingBindingElement
    • 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

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.

2 responses to “Theoretical introduction of Custom Binding in WCF”

  1. Hi, with 2010 (as soon as I switch to custombinding I cannot debug from the client code). With httpbinding it works with no issues.
    PS: I have enabled debugging on the server.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at