OperationMessageCollection.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // System.Web.Services.Description.OperationMessageCollection.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2002
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System.Web.Services;
  30. namespace System.Web.Services.Description {
  31. public sealed class OperationMessageCollection : ServiceDescriptionBaseCollection {
  32. #region Constructors
  33. internal OperationMessageCollection (Operation operation)
  34. : base (operation)
  35. {
  36. }
  37. #endregion // Constructors
  38. #region Properties
  39. public OperationFlow Flow {
  40. get {
  41. switch (Count) {
  42. case 1:
  43. if (this[0] is OperationInput)
  44. return OperationFlow.OneWay;
  45. else
  46. return OperationFlow.Notification;
  47. case 2:
  48. if (this[0] is OperationInput)
  49. return OperationFlow.RequestResponse;
  50. else
  51. return OperationFlow.SolicitResponse;
  52. }
  53. return OperationFlow.None;
  54. }
  55. }
  56. public OperationInput Input {
  57. get {
  58. foreach (object message in List)
  59. if (message is OperationInput)
  60. return (OperationInput) message;
  61. return null;
  62. }
  63. }
  64. public OperationMessage this [int index] {
  65. get { return (OperationMessage) List[index]; }
  66. set { List[index] = value; }
  67. }
  68. public OperationOutput Output {
  69. get {
  70. foreach (object message in List)
  71. if (message is OperationOutput)
  72. return (OperationOutput) message;
  73. return null;
  74. }
  75. }
  76. internal OperationFault Fault {
  77. get {
  78. foreach (object message in List)
  79. if (message is OperationFault)
  80. return (OperationFault) message;
  81. return null;
  82. }
  83. }
  84. #endregion // Properties
  85. #region Methods
  86. public int Add (OperationMessage operationMessage)
  87. {
  88. Insert (Count, operationMessage);
  89. return (Count - 1);
  90. }
  91. public bool Contains (OperationMessage operationMessage)
  92. {
  93. return List.Contains (operationMessage);
  94. }
  95. public void CopyTo (OperationMessage[] array, int index)
  96. {
  97. List.CopyTo (array, index);
  98. }
  99. public int IndexOf (OperationMessage operationMessage)
  100. {
  101. return List.IndexOf (operationMessage);
  102. }
  103. public void Insert (int index, OperationMessage operationMessage)
  104. {
  105. List.Insert (index, operationMessage);
  106. }
  107. protected override void OnInsert (int index, object value)
  108. {
  109. if (Count == 0)
  110. return;
  111. if (Count == 1 && value.GetType() != this[0].GetType())
  112. return;
  113. throw new InvalidOperationException ("The operation object can only contain one input and one output message.");
  114. }
  115. protected override void OnSet (int index, object oldValue, object newValue)
  116. {
  117. if (oldValue.GetType () != newValue.GetType ())
  118. throw new InvalidOperationException ("The message types of the old and new value are not the same.");
  119. base.OnSet (index, oldValue, newValue);
  120. }
  121. protected override void OnValidate (object value)
  122. {
  123. if (value == null)
  124. throw new ArgumentException("The message object is a null reference.");
  125. if (!(value is OperationInput || value is OperationOutput))
  126. throw new ArgumentException ("The message object is not an input or an output message.");
  127. }
  128. public void Remove (OperationMessage operationMessage)
  129. {
  130. List.Remove (operationMessage);
  131. }
  132. protected override void SetParent (object value, object parent)
  133. {
  134. ((OperationMessage) value).SetParent ((Operation) parent);
  135. }
  136. #endregion // Methods
  137. }
  138. }