I thought I'd share the binding inspector program I wrote a few months ago to explore the different settings for the standard bindings series of articles.

You can access all of the articles in the series here:

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;

namespace BindingInspector
{
class PropertyNameComparer : IComparer<PropertyInfo>
{
public int Compare(PropertyInfo x, PropertyInfo y)
{
return String.Compare(x.Name, y.Name);
}
}

class BindingInspector
{
static string NEVER = "***";
static string NULL = "NULL";

static bool freezeSeenProperties;
static List<string> expandedProperties = new List<string>();
static Dictionary<string,string> seenProperties = new Dictionary<string,string>();
static List<Type> hiddenElements = new List<Type>();
static StreamWriter writer;

static void Main(string[] args)
{
expandedProperties.Add("ReaderQuotas");
expandedProperties.Add("ReliableSession");
expandedProperties.Add("MsmqTransportSecurity");

hiddenElements.Add(typeof(AsymmetricSecurityBindingElement));
hiddenElements.Add(typeof(TransportSecurityBindingElement));
hiddenElements.Add(typeof(SymmetricSecurityBindingElement));

writer = File.CreateText("basichttp.html");
BasicHttpMain();
writer.Close();
writer = File.CreateText("nettcp.html");
NetTcpMain();
writer.Close();
writer = File.CreateText("netnamedpipe.html");
NetNamedPipeMain();
writer.Close();
writer = File.CreateText("wshttp.html");
WSHttpMain();
writer.Close();
writer = File.CreateText("wsdualhttp.html");
WSDualHttpMain();
writer.Close();
writer = File.CreateText("wsfederationhttp.html");
WSFederationHttpMain();
writer.Close();
writer = File.CreateText("netmsmq.html");
NetMsmq();
writer.Close();
writer = File.CreateText("netpeertcp.html");
NetPeerTcp();
writer.Close();
}

static void BasicHttpMain()
{
BasicHttpBinding binding1 = new BasicHttpBinding();
binding1.Security.Mode = BasicHttpSecurityMode.None;

BasicHttpBinding binding2 = new BasicHttpBinding();
binding2.Security.Mode = BasicHttpSecurityMode.Transport;

BasicHttpBinding binding3 = new BasicHttpBinding();
binding3.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
binding3.Security.Mode = BasicHttpSecurityMode.Message;

BasicHttpBinding binding4 = new BasicHttpBinding();
binding4.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;

BasicHttpBinding binding5 = new BasicHttpBinding();
binding5.Security.Mode = BasicHttpSecurityMode.None;
binding5.MessageEncoding = WSMessageEncoding.Mtom;

AnalyzeBindings(binding1, binding2, binding3, binding4, binding5);
}

static void NetTcpMain()
{
NetTcpBinding binding1 = new NetTcpBinding();
binding1.Security.Mode = SecurityMode.None;

NetTcpBinding binding2 = new NetTcpBinding();
binding2.Security.Mode = SecurityMode.Transport;

NetTcpBinding binding3 = new NetTcpBinding();
binding3.Security.Mode = SecurityMode.Message;

NetTcpBinding binding4 = new NetTcpBinding();
binding4.Security.Mode = SecurityMode.TransportWithMessageCredential;

NetTcpBinding binding5 = new NetTcpBinding();
binding5.Security.Mode = SecurityMode.None;
binding5.ReliableSession.Enabled = true;

AnalyzeBindings(binding1, binding2, binding3, binding4, binding5);
}

static void NetNamedPipeMain()
{
NetNamedPipeBinding binding1 = new NetNamedPipeBinding();
binding1.Security.Mode = NetNamedPipeSecurityMode.None;

NetNamedPipeBinding binding2 = new NetNamedPipeBinding();
binding2.Security.Mode = NetNamedPipeSecurityMode.Transport;

AnalyzeBindings(binding1, binding2);
}

static void WSHttpMain()
{
WSHttpBinding binding1 = new WSHttpBinding();
binding1.Security.Mode = SecurityMode.None;

WSHttpBinding binding2 = new WSHttpBinding();
binding2.Security.Mode = SecurityMode.Transport;

WSHttpBinding binding3 = new WSHttpBinding();
binding3.Security.Mode = SecurityMode.Message;

WSHttpBinding binding4 = new WSHttpBinding();
binding4.Security.Mode = SecurityMode.TransportWithMessageCredential;

WSHttpBinding binding5 = new WSHttpBinding();
binding5.Security.Mode = SecurityMode.None;
binding5.ReliableSession.Enabled = true;

WSHttpBinding binding6 = new WSHttpBinding();
binding6.Security.Mode = SecurityMode.None;
binding6.MessageEncoding = WSMessageEncoding.Mtom;

AnalyzeBindings(binding1, binding2, binding3, binding4, binding5, binding6);
}

static void WSDualHttpMain()
{
WSDualHttpBinding binding1 = new WSDualHttpBinding();
binding1.Security.Mode = WSDualHttpSecurityMode.None;

WSDualHttpBinding binding2 = new WSDualHttpBinding();
binding2.Security.Mode = WSDualHttpSecurityMode.Message;

WSDualHttpBinding binding3 = new WSDualHttpBinding();
binding3.Security.Mode = WSDualHttpSecurityMode.None;
binding3.MessageEncoding = WSMessageEncoding.Mtom;

AnalyzeBindings(binding1, binding2, binding3);
}

static void WSFederationHttpMain()
{
WSFederationHttpBinding binding1 = new WSFederationHttpBinding();
binding1.Security.Mode = WSFederationHttpSecurityMode.None;

WSFederationHttpBinding binding2 = new WSFederationHttpBinding();
binding2.Security.Mode = WSFederationHttpSecurityMode.Message;

WSFederationHttpBinding binding3 = new WSFederationHttpBinding();
binding3.Security.Mode = WSFederationHttpSecurityMode.TransportWithMessageCredential;

WSFederationHttpBinding binding4 = new WSFederationHttpBinding();
binding4.Security.Mode = WSFederationHttpSecurityMode.None;
binding4.MessageEncoding = WSMessageEncoding.Mtom;

AnalyzeBindings(binding1, binding2, binding3, binding4);
}

static void NetMsmq()
{
NetMsmqBinding binding1 = new NetMsmqBinding();
binding1.Security.Mode = NetMsmqSecurityMode.None;

NetMsmqBinding binding2 = new NetMsmqBinding();
binding2.Security.Mode = NetMsmqSecurityMode.Transport;

NetMsmqBinding binding3 = new NetMsmqBinding();
binding3.Security.Mode = NetMsmqSecurityMode.Message;

NetMsmqBinding binding4 = new NetMsmqBinding();
binding4.Security.Mode = NetMsmqSecurityMode.Both;

AnalyzeBindings(binding1, binding2, binding3, binding4);
}

static void NetPeerTcp()
{
NetPeerTcpBinding binding1 = new NetPeerTcpBinding();
binding1.Security.Mode = SecurityMode.None;

NetPeerTcpBinding binding2 = new NetPeerTcpBinding();
binding2.Security.Mode = SecurityMode.Transport;

NetPeerTcpBinding binding3 = new NetPeerTcpBinding();
binding3.Security.Mode = SecurityMode.Message;

NetPeerTcpBinding binding4 = new NetPeerTcpBinding();
binding4.Security.Mode = SecurityMode.TransportWithMessageCredential;

AnalyzeBindings(binding1, binding2, binding3, binding4);
}

static void ResetSeenProperties()
{
seenProperties.Clear();
freezeSeenProperties = false;
seenProperties.Add("Max", NEVER);
seenProperties.Add("Default", NEVER);
seenProperties.Add("IdentityVerifier", NEVER);
seenProperties.Add("MessageEncoding", NEVER);
seenProperties.Add("MessageVersion", NEVER);
seenProperties.Add("Name", NEVER);
seenProperties.Add("Security", NEVER);
seenProperties.Add("WriteEncoding", NEVER);
}

static void AnalyzeBindings(params Binding[] bindings)
{
ResetSeenProperties();
StreamWriter tempWriter = writer;
writer = StreamWriter.Null;
foreach (Binding binding in bindings)
{
AnalyzeBinding(binding);
}
freezeSeenProperties = true;
writer = tempWriter;

Type bindingType = bindings[0].GetType();
writer.WriteLine("<P><B>{0}</B></P>", bindingType.ToString());
ReflectObject(bindings[0], "");
ResetSeenProperties();
foreach (Binding binding in bindings)
{
AnalyzeBinding(binding);
freezeSeenProperties = true;
}
}

static void AnalyzeBinding(Binding binding)
{
writer.WriteLine("<OL>");
foreach (BindingElement element in binding.CreateBindingElements())
{
Type bindingElementType = element.GetType();
writer.WriteLine("<LI>" + bindingElementType.ToString());
if (!hiddenElements.Contains(bindingElementType))
{
ReflectObject(element, "");
}
writer.WriteLine("</LI>");
}
writer.WriteLine("</OL>");
}

static void ReflectObject(Object o, string indent)
{
bool writePreBlock = indent == "";
bool firstProperty = true;
Type type = o.GetType();
PropertyInfo[] properties = type.GetProperties();
Array.Sort(properties, new PropertyNameComparer());
foreach (PropertyInfo info in properties)
{
object summary = info.GetValue(o, null);
string lastPropertyText;
seenProperties.TryGetValue(info.Name, out lastPropertyText);
if (lastPropertyText == NEVER)
{
continue;
}
if (summary == null && lastPropertyText == NULL)
{
continue;
}
if (summary != null && summary.ToString() == lastPropertyText)
{
continue;
}
if (!freezeSeenProperties)
{
if (summary == null)
{
seenProperties[info.Name] = NULL;
}
else { seenProperties[info.Name] = summary.ToString(); } } if (firstProperty && writePreBlock)
{
writer.WriteLine("<PRE>");
firstProperty = false;
}
writer.Write("{0}: ", indent + info.Name);
if (expandedProperties.Contains(info.Name))
{
writer.WriteLine();
ReflectObject(summary, indent + " ");
continue;
}
if (summary == null)
{
writer.WriteLine("<NULL>");
}
else { writer.WriteLine(summary.ToString().Replace("\n", "\n" + indent + " "));
}
}
if (!firstProperty && writePreBlock)
{
writer.WriteLine("</PRE>");
}
}
}
}