ServiceEndpointCollection.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Description
  5. {
  6. using System.ServiceModel;
  7. using System.ServiceModel.Channels;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Xml;
  11. using System.Runtime.Serialization;
  12. public class ServiceEndpointCollection : Collection<ServiceEndpoint>
  13. {
  14. internal ServiceEndpointCollection()
  15. {
  16. }
  17. public ServiceEndpoint Find(Type contractType)
  18. {
  19. if (contractType == null)
  20. {
  21. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractType");
  22. }
  23. foreach (ServiceEndpoint endpoint in this)
  24. {
  25. if (endpoint != null && endpoint.Contract.ContractType == contractType)
  26. {
  27. return endpoint;
  28. }
  29. }
  30. return null;
  31. }
  32. public ServiceEndpoint Find(XmlQualifiedName contractName)
  33. {
  34. if (contractName == null)
  35. {
  36. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractName");
  37. }
  38. foreach (ServiceEndpoint endpoint in this)
  39. {
  40. if (endpoint != null && endpoint.Contract.Name == contractName.Name && endpoint.Contract.Namespace == contractName.Namespace)
  41. {
  42. return endpoint;
  43. }
  44. }
  45. return null;
  46. }
  47. public ServiceEndpoint Find(Type contractType, XmlQualifiedName bindingName)
  48. {
  49. if (contractType == null)
  50. {
  51. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractType");
  52. }
  53. if (bindingName == null)
  54. {
  55. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bindingName");
  56. }
  57. foreach (ServiceEndpoint endpoint in this)
  58. {
  59. if (endpoint != null && endpoint.Contract.ContractType == contractType &&
  60. endpoint.Binding.Name == bindingName.Name &&
  61. endpoint.Binding.Namespace == bindingName.Namespace)
  62. {
  63. return endpoint;
  64. }
  65. }
  66. return null;
  67. }
  68. public ServiceEndpoint Find(XmlQualifiedName contractName, XmlQualifiedName bindingName)
  69. {
  70. if (contractName == null)
  71. {
  72. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractName");
  73. }
  74. if (bindingName == null)
  75. {
  76. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bindingName");
  77. }
  78. foreach (ServiceEndpoint endpoint in this)
  79. {
  80. if (endpoint != null && endpoint.Contract.Name == contractName.Name &&
  81. endpoint.Contract.Namespace == contractName.Namespace &&
  82. endpoint.Binding.Name == bindingName.Name &&
  83. endpoint.Binding.Namespace == bindingName.Namespace)
  84. {
  85. return endpoint;
  86. }
  87. }
  88. return null;
  89. }
  90. public ServiceEndpoint Find(Uri address)
  91. {
  92. if (address == null)
  93. {
  94. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address");
  95. }
  96. foreach (ServiceEndpoint endpoint in this)
  97. {
  98. if (endpoint != null && endpoint.Address.Uri == address)
  99. {
  100. return endpoint;
  101. }
  102. }
  103. return null;
  104. }
  105. public Collection<ServiceEndpoint> FindAll(Type contractType)
  106. {
  107. if (contractType == null)
  108. {
  109. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractType");
  110. }
  111. Collection<ServiceEndpoint> results = new Collection<ServiceEndpoint>();
  112. foreach (ServiceEndpoint endpoint in this)
  113. {
  114. if (endpoint != null && endpoint.Contract.ContractType == contractType)
  115. {
  116. results.Add(endpoint);
  117. }
  118. }
  119. return results;
  120. }
  121. public Collection<ServiceEndpoint> FindAll(XmlQualifiedName contractName)
  122. {
  123. if (contractName == null)
  124. {
  125. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractName");
  126. }
  127. Collection<ServiceEndpoint> results = new Collection<ServiceEndpoint>();
  128. foreach (ServiceEndpoint endpoint in this)
  129. {
  130. if (endpoint != null && endpoint.Contract.Name == contractName.Name && endpoint.Contract.Namespace == contractName.Namespace)
  131. {
  132. results.Add(endpoint);
  133. }
  134. }
  135. return results;
  136. }
  137. protected override void InsertItem(int index, ServiceEndpoint item)
  138. {
  139. if (item == null)
  140. {
  141. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("item");
  142. }
  143. base.InsertItem(index, item);
  144. }
  145. protected override void SetItem(int index, ServiceEndpoint item)
  146. {
  147. if (item == null)
  148. {
  149. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("item");
  150. }
  151. base.SetItem(index, item);
  152. }
  153. }
  154. }