ServiceDescriptionCollection.cs 3.2 KB

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