Programmatically finding Binding Elements in WCF Binding

No.of Views1672
Bookmarked0 times
Downloads 
Votes0
By  Dhananjay Kumar   On  05 Mar 2011 05:03:01
Tag : WCF , General
Binding is one of the important aspect of WCF Programming. It deals with, “How Service and client will talk to each other?” Binding is made up of different binding elements. When different binding elements are stacked together they form a Binding. Different binding types are made up of different binding elements.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Binding is one of the important aspect of WCF Programming. It deals with, “How Service and client will talk to each other?” Binding is made up of different binding elements. When different binding elements are stacked together they form a Binding. Different binding types are made up of different binding elements.

Always a question arises that, “What are the different binding elements of a particular binding? “

And we can find solution of above question through code. What all we need to do

1.    Create instance of Binding
2.    Enumerate through Binding elements.

We are going to create console application to enumerate through all the binding elements in a binding.
Add below references in console application project, 

Image Loading

We are going to write a function. This function will take object of a Binding as input parameter and prints all the binding elements. 

Image Loading

Above function is very simple, just enumerating above all the binding elements.
We may call above function as below,

Image Loading

Full source code is as below,

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels; 
 
namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
 
            EnumerateBindingElements(new BasicHttpBinding());
            EnumerateBindingElements(new NetMsmqBinding());
            EnumerateBindingElements(new WSHttpBinding());
            Console.ReadKey(true);
 
        }
 
        static void EnumerateBindingElements(Binding binding)
        {
            Console.WriteLine("Binding : " + binding.GetType().Name);
            BindingElementCollection bindingElements = binding.CreateBindingElements();
            foreach (BindingElement e in bindingElements)
            {
                Console.WriteLine(e.GetType().FullName);
            }          
 
        }
    }
}

Output
 

Image Loading

Hope help and thank you for reading.

 
Sign Up to vote for this article
 
About Author
 
Dhananjay Kumar
Occupation-Software Engineer
Company-Infosys Technolgies,Pune
Member Type-Gold
Location-India
Joined date-20 Jul 2009
Home Page-http://dhananjaykumar.net/
Blog Page-http://dhananjaykumar.net/
Dhananjay Kumar is Microsoft MVP on connected system. He blogs at http://dhananjaykumar.net/ . You can follow him http://twitter.com/debugmode_/ and reach him at dhananjay.25july@gmail.com
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top