Programmatically Finding Binding Elements in WCF Binding
How to enumerate the binding elements in a binding.
Binding is one of the important aspects of WCF Programming. It deals with, "How Service and client will talk to each other?" Binding is made up of mutiple binding elements. When different binding elements are stacked together they form a Binding. Different binding types are made up of different binding elements.
Always the question arises, "What are the different binding elements of a particular binding?"
And we can find the solution of the above question through code. What all we need to do:
- Create instance of Binding
- Enumerate through Binding elements.
We are going to create a console application to enumerate through all the binding elements in a binding.
Add the following references to the console application project:
Next we are going to write a function. This function will take an object for a Binding as it's input parameter and then prints all the binding elements.
The above function is very simple; it just enumerates above all the binding elements.
We may call the above function as below:
static void Main(string args)
static void EnumerateBindingElements(Binding binding)
Console.WriteLine("Binding : " + binding.GetType().Name);
BindingElementCollection bindingElements = binding.CreateBindingElements();
foreach (BindingElement e in bindingElements)