ServiceDescriptionCollection.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // System.Web.Services.Description.ServiceDescriptionCollection.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Copyright (C) Tim Coleman, 2002
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.Web.Services;
  31. using System.Xml;
  32. namespace System.Web.Services.Description {
  33. public sealed class ServiceDescriptionCollection : ServiceDescriptionBaseCollection {
  34. #region Constructors
  35. public ServiceDescriptionCollection ()
  36. : base (null)
  37. {
  38. }
  39. #endregion // Constructors
  40. #region Properties
  41. public ServiceDescription this [int index] {
  42. get {
  43. if (index < 0 || index > Count)
  44. throw new ArgumentOutOfRangeException ();
  45. return (ServiceDescription) List[index];
  46. }
  47. set { List [index] = value; }
  48. }
  49. public ServiceDescription this [string ns] {
  50. get {
  51. return (ServiceDescription) Table[ns];
  52. }
  53. }
  54. #endregion // Properties
  55. #region Methods
  56. public int Add (ServiceDescription serviceDescription)
  57. {
  58. Insert (Count, serviceDescription);
  59. return (Count - 1);
  60. }
  61. public bool Contains (ServiceDescription serviceDescription)
  62. {
  63. return List.Contains (serviceDescription);
  64. }
  65. public void CopyTo (ServiceDescription[] array, int index)
  66. {
  67. List.CopyTo (array, index);
  68. }
  69. public Binding GetBinding (XmlQualifiedName name)
  70. {
  71. ServiceDescription desc = (ServiceDescription) Table[name.Namespace];
  72. if (desc != null) {
  73. foreach (Binding binding in desc.Bindings)
  74. if (binding.Name == name.Name)
  75. return binding;
  76. }
  77. throw new InvalidOperationException ("Binding '" + name + "' not found");
  78. }
  79. protected override string GetKey (object value)
  80. {
  81. return ((ServiceDescription) value).TargetNamespace;
  82. }
  83. public Message GetMessage (XmlQualifiedName name)
  84. {
  85. ServiceDescription desc = (ServiceDescription) Table[name.Namespace];
  86. if (desc != null) {
  87. foreach (Message message in desc.Messages)
  88. if (message.Name == name.Name)
  89. return message;
  90. }
  91. throw new InvalidOperationException ("Message '" + name + "' not found");
  92. }
  93. public PortType GetPortType (XmlQualifiedName name)
  94. {
  95. ServiceDescription desc = (ServiceDescription) Table[name.Namespace];
  96. if (desc != null) {
  97. foreach (PortType portType in desc.PortTypes)
  98. if (portType.Name == name.Name)
  99. return portType;
  100. }
  101. throw new InvalidOperationException ("Port type '" + name + "' not found");
  102. }
  103. public Service GetService (XmlQualifiedName name)
  104. {
  105. ServiceDescription desc = (ServiceDescription) Table[name.Namespace];
  106. if (desc != null) {
  107. foreach (Service service in desc.Services)
  108. if (service.Name == name.Name)
  109. return service;
  110. }
  111. throw new InvalidOperationException ("Service '" + name + "' not found");
  112. }
  113. public int IndexOf (ServiceDescription serviceDescription)
  114. {
  115. return List.IndexOf (serviceDescription);
  116. }
  117. public void Insert (int index, ServiceDescription serviceDescription)
  118. {
  119. List.Insert (index, serviceDescription);
  120. }
  121. public void Remove (ServiceDescription serviceDescription)
  122. {
  123. List.Remove (serviceDescription);
  124. }
  125. #endregion // Methods
  126. }
  127. }