Skip to content

Instantly share code, notes, and snippets.

@rahulsahay19
Created February 27, 2017 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulsahay19/b985ea7633a4e0a866c4d6fe56faff03 to your computer and use it in GitHub Desktop.
Save rahulsahay19/b985ea7633a4e0a866c4d6fe56faff03 to your computer and use it in GitHub Desktop.
FetchingBindings
//Method to Apply Endpoint behaviors
private static void ApplyEndPointBehaviors(object factory)
{
((ChannelFactory)factory).Endpoint.Behaviors.Add(new PortalContextHeaderClientBehavior());
((ChannelFactory)factory).Endpoint.Behaviors.Add(new CorpFaultBehavior());
}
//Method to collect all EndPoint addresses
private static List<Uri> ApplyAddressCollection(out List<string> contractCollection, out object address,
out ClientSection clientSection)
{
List<Uri> addressCollection = new List<Uri>();
contractCollection = new List<string>();
List<string> bindinCollection = new List<string>();
address = null;
clientSection = GetClientSection();
for (int j = 0; j < clientSection.Endpoints.Count; j++)
{
addressCollection.Add(clientSection.Endpoints[j].Address);
contractCollection.Add(clientSection.Endpoints[j].Contract);
bindinCollection.Add(clientSection.Endpoints[j].Binding);
}
return addressCollection;
}
//Method to apply the Binding Collection
private static Binding ApplyBindingConfiguration(BindingsSection section, string bindingName, Binding binding)
{
foreach (var bindingCollection in section.BindingCollections)
{
if (bindingCollection.BindingName.Equals(bindingName))
{
for (int i = 0; i < bindingCollection.ConfiguredBindings.Count; i++)
{
if (bindingCollection.ConfiguredBindings.Count > 0)
{
var bindingElement = bindingCollection.ConfiguredBindings[i];
binding = (Binding)Activator.CreateInstance(bindingCollection.BindingType);
binding.Name = bindingElement.Name;
bindingElement.ApplyConfiguration(binding);
}
}
}
}
return binding;
}
//Method to fetch Client Section
private static ClientSection GetClientSection()
{
ClientSection clientSection = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");
return clientSection;
}
//This will return all the bindings from the config file
private static BindingsSection GetBindingsSection()
{
BindingsSection bindingsSection = (BindingsSection)ConfigurationManager.GetSection("system.serviceModel/bindings");
return bindingsSection;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment