Tuesday, December 18, 2007

BindingElements List

Here is a simple code to display BindingElements for WCF Default Bindings (for .NET Framework version 3.0) --

System.Reflection.Assembly asm;
asm = Assembly.Load("System.ServiceModel");
foreach (Type obj in asm.GetTypes())
{
if ((obj.Name.EndsWith("Binding")) && (obj.IsAbstract == false)&&((obj.Namespace == "System.ServiceModel")||(obj.Namespace == "System.ServiceModel.MsmqIntegration")))
{
System.ServiceModel.Channels.Binding MyBinding = (System.ServiceModel.Channels.Binding)asm.CreateInstance(obj.FullName);
Console.WriteLine("\'Binding Elements\' for Binding {0}", MyBinding.GetType().FullName);
try
{
foreach (System.ServiceModel.Channels.BindingElement element in MyBinding.CreateBindingElements())
{
Console.WriteLine("\t{0}", element.GetType().Name);
}
}
catch (InvalidOperationException ex)//If PNRP is not enabled on the machine then NetPeerTcpBinding.CreateBindingElements() raises an InvalidOperationException
{
Console.WriteLine("Exception occured at {0} \n\t {1}", MyBinding.Name, ex.Message);
}
Console.WriteLine("===========================");
}
}
Console.ReadLine();


=============================================================================
From the result of the above , we can see that, apart from MsmqIntegrationBinding, all other bindings has a element each for Transport and Encoding.

No comments:

Labels