Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. //Method to Apply Endpoint behaviors
  2. private static void ApplyEndPointBehaviors(object factory)
  3. {
  4. ((ChannelFactory)factory).Endpoint.Behaviors.Add(new PortalContextHeaderClientBehavior());
  5. ((ChannelFactory)factory).Endpoint.Behaviors.Add(new CorpFaultBehavior());
  6. }
  7.  
  8. //Method to collect all EndPoint addresses
  9. private static List<Uri> ApplyAddressCollection(out List<string> contractCollection, out object address,
  10. out ClientSection clientSection)
  11. {
  12. List<Uri> addressCollection = new List<Uri>();
  13. contractCollection = new List<string>();
  14. List<string> bindinCollection = new List<string>();
  15. address = null;
  16.  
  17. clientSection = GetClientSection();
  18.  
  19. for (int j = 0; j < clientSection.Endpoints.Count; j++)
  20. {
  21. addressCollection.Add(clientSection.Endpoints[j].Address);
  22. contractCollection.Add(clientSection.Endpoints[j].Contract);
  23. bindinCollection.Add(clientSection.Endpoints[j].Binding);
  24. }
  25. return addressCollection;
  26. }
  27.  
  28. //Method to apply the Binding Collection
  29. private static Binding ApplyBindingConfiguration(BindingsSection section, string bindingName, Binding binding)
  30. {
  31. foreach (var bindingCollection in section.BindingCollections)
  32. {
  33. if (bindingCollection.BindingName.Equals(bindingName))
  34. {
  35. for (int i = 0; i < bindingCollection.ConfiguredBindings.Count; i++)
  36. {
  37. if (bindingCollection.ConfiguredBindings.Count > 0)
  38. {
  39. var bindingElement = bindingCollection.ConfiguredBindings[i];
  40. binding = (Binding)Activator.CreateInstance(bindingCollection.BindingType);
  41. binding.Name = bindingElement.Name;
  42. bindingElement.ApplyConfiguration(binding);
  43. }
  44. }
  45. }
  46. }
  47. return binding;
  48. }
  49.  
  50. //Method to fetch Client Section
  51. private static ClientSection GetClientSection()
  52. {
  53. ClientSection clientSection = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");
  54. return clientSection;
  55.  
  56. }
  57.  
  58.  
  59. //This will return all the bindings from the config file
  60. private static BindingsSection GetBindingsSection()
  61. {
  62. BindingsSection bindingsSection = (BindingsSection)ConfigurationManager.GetSection("system.serviceModel/bindings");
  63.  
  64. return bindingsSection;
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement