Created
February 27, 2017 13:27
-
-
Save rahulsahay19/b985ea7633a4e0a866c4d6fe56faff03 to your computer and use it in GitHub Desktop.
FetchingBindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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