ServiceDescriptionCollection.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #if !TARGET_JVM //code generation is not supported
  35. ServiceDescriptionImporter importer;
  36. #endif
  37. #region Constructors
  38. public ServiceDescriptionCollection ()
  39. : base (null)
  40. {
  41. }
  42. #endregion // Constructors
  43. #region Properties
  44. public ServiceDescription this [int index] {
  45. get {
  46. if (index < 0 || index > Count)
  47. throw new ArgumentOutOfRangeException ();
  48. return (ServiceDescription) List[index];
  49. }
  50. set { List [index] = value; }
  51. }
  52. public ServiceDescription this [string ns] {
  53. get {
  54. return (ServiceDescription) Table[ns];
  55. }
  56. }
  57. #endregion // Properties
  58. #region Methods
  59. #if !TARGET_JVM //code generation is not supported
  60. internal void SetImporter (ServiceDescriptionImporter i)
  61. {
  62. importer = i;
  63. }
  64. #endif
  65. public int Add (ServiceDescription serviceDescription)
  66. {
  67. Insert (Count, serviceDescription);
  68. return (Count - 1);
  69. }
  70. public bool Contains (ServiceDescription serviceDescription)
  71. {
  72. return List.Contains (serviceDescription);
  73. }
  74. public void CopyTo (ServiceDescription[] array, int index)
  75. {
  76. List.CopyTo (array, index);
  77. }
  78. public Binding GetBinding (XmlQualifiedName name)
  79. {
  80. ServiceDescription desc = (ServiceDescription) Table[name.Namespace];
  81. if (desc != null) {
  82. foreach (Binding binding in desc.Bindings)
  83. if (binding.Name == name.Name)
  84. return binding;
  85. }
  86. throw new InvalidOperationException ("Binding '" + name + "' not found");
  87. }
  88. protected override string GetKey (object value)
  89. {
  90. return ((ServiceDescription) value).TargetNamespace;
  91. }
  92. public Message GetMessage (XmlQualifiedName name)
  93. {
  94. ServiceDescription desc = (ServiceDescription) Table[name.Namespace];
  95. if (desc != null) {
  96. foreach (Message message in desc.Messages)
  97. if (message.Name == name.Name)
  98. return message;
  99. }
  100. throw new InvalidOperationException ("Message '" + name + "' not found");
  101. }
  102. public PortType GetPortType (XmlQualifiedName name)
  103. {
  104. ServiceDescription desc = (ServiceDescription) Table[name.Namespace];
  105. if (desc != null) {
  106. foreach (PortType portType in desc.PortTypes)
  107. if (portType.Name == name.Name)
  108. return portType;
  109. }
  110. throw new InvalidOperationException ("Port type '" + name + "' not found");
  111. }
  112. public Service GetService (XmlQualifiedName name)
  113. {
  114. ServiceDescription desc = (ServiceDescription) Table[name.Namespace];
  115. if (desc != null) {
  116. foreach (Service service in desc.Services)
  117. if (service.Name == name.Name)
  118. return service;
  119. }
  120. throw new InvalidOperationException ("Service '" + name + "' not found");
  121. }
  122. public int IndexOf (ServiceDescription serviceDescription)
  123. {
  124. return List.IndexOf (serviceDescription);
  125. }
  126. public void Insert (int index, ServiceDescription serviceDescription)
  127. {
  128. List.Insert (index, serviceDescription);
  129. OnInsertComplete (index, serviceDescription);
  130. }
  131. public void Remove (ServiceDescription serviceDescription)
  132. {
  133. List.Remove (serviceDescription);
  134. }
  135. #if NET_2_0
  136. [MonoTODO]
  137. protected override
  138. #endif
  139. void OnInsertComplete (int index, object item)
  140. {
  141. base.OnInsertComplete (index, item);
  142. }
  143. #if NET_2_0
  144. [MonoTODO]
  145. protected override void SetParent (object value, object parent)
  146. {
  147. }
  148. #endif
  149. #endregion // Methods
  150. }
  151. }