ServiceDescriptionCollection.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // System.Web.Services.Description.ServiceDescriptionCollection.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2002
  8. //
  9. using System.Web.Services;
  10. using System.Xml;
  11. namespace System.Web.Services.Description {
  12. public sealed class ServiceDescriptionCollection : ServiceDescriptionBaseCollection {
  13. #region Constructors
  14. public ServiceDescriptionCollection ()
  15. : base (null)
  16. {
  17. }
  18. #endregion // Constructors
  19. #region Properties
  20. public ServiceDescription this [int index] {
  21. get {
  22. if (index < 0 || index > Count)
  23. throw new ArgumentOutOfRangeException ();
  24. return (ServiceDescription) List[index];
  25. }
  26. set { List [index] = value; }
  27. }
  28. public ServiceDescription this [string ns] {
  29. get {
  30. int index = IndexOf ((ServiceDescription) Table[ns]);
  31. if (index >= 0)
  32. return this[index];
  33. return null;
  34. }
  35. }
  36. #endregion // Properties
  37. #region Methods
  38. public int Add (ServiceDescription serviceDescription)
  39. {
  40. Insert (Count, serviceDescription);
  41. return (Count - 1);
  42. }
  43. public bool Contains (ServiceDescription serviceDescription)
  44. {
  45. return List.Contains (serviceDescription);
  46. }
  47. public void CopyTo (ServiceDescription[] array, int index)
  48. {
  49. List.CopyTo (array, index);
  50. }
  51. public Binding GetBinding (XmlQualifiedName name)
  52. {
  53. foreach (object value in List)
  54. foreach (Binding binding in ((ServiceDescription) value).Bindings)
  55. if (binding.Name == name.Name)
  56. return binding;
  57. throw new Exception ();
  58. }
  59. protected override string GetKey (object value)
  60. {
  61. if (!(value is ServiceDescription))
  62. throw new InvalidCastException ();
  63. return ((ServiceDescription) value).TargetNamespace;
  64. }
  65. public Message GetMessage (XmlQualifiedName name)
  66. {
  67. foreach (object value in List)
  68. foreach (Message message in ((ServiceDescription) value).Messages)
  69. if (message.Name == name.Name)
  70. return message;
  71. throw new Exception ();
  72. }
  73. public PortType GetPortType (XmlQualifiedName name)
  74. {
  75. foreach (object value in List)
  76. foreach (PortType portType in ((ServiceDescription) value).PortTypes)
  77. if (portType.Name == name.Name)
  78. return portType;
  79. throw new Exception ();
  80. }
  81. public Service GetService (XmlQualifiedName name)
  82. {
  83. foreach (object value in List)
  84. foreach (Service service in ((ServiceDescription) value).Services)
  85. if (service.Name == name.Name)
  86. return service;
  87. throw new Exception ();
  88. }
  89. public int IndexOf (ServiceDescription serviceDescription)
  90. {
  91. return List.IndexOf (serviceDescription);
  92. }
  93. public void Insert (int index, ServiceDescription serviceDescription)
  94. {
  95. List.Insert (index, serviceDescription);
  96. }
  97. public void Remove (ServiceDescription serviceDescription)
  98. {
  99. List.Remove (serviceDescription);
  100. }
  101. #endregion // Methods
  102. }
  103. }