OperationMessageCollection.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. using System.Web.Services;
  10. namespace System.Web.Services.Description {
  11. public sealed class OperationMessageCollection : ServiceDescriptionBaseCollection {
  12. #region Fields
  13. Operation operation;
  14. #endregion // Fields
  15. #region Constructors
  16. internal OperationMessageCollection (Operation operation)
  17. {
  18. this.operation = operation;
  19. }
  20. #endregion // Constructors
  21. #region Properties
  22. public OperationFlow Flow {
  23. [MonoTODO ("Verify default return value.")]
  24. get {
  25. switch (Count) {
  26. case 1:
  27. if (this[0] is OperationInput)
  28. return OperationFlow.OneWay;
  29. else
  30. return OperationFlow.Notification;
  31. break;
  32. case 2:
  33. if (this[0] is OperationInput)
  34. return OperationFlow.RequestResponse;
  35. else
  36. return OperationFlow.SolicitResponse;
  37. break;
  38. }
  39. return OperationFlow.None; // .NET says default is SolicitResponse. Verify this.
  40. }
  41. }
  42. public OperationInput Input {
  43. get {
  44. foreach (object message in List)
  45. if (message is OperationInput)
  46. return (OperationInput) message;
  47. return null;
  48. }
  49. }
  50. public OperationMessage this [int index] {
  51. get { return (OperationMessage) List[index]; }
  52. set { List[index] = value; }
  53. }
  54. public OperationOutput Output {
  55. get {
  56. foreach (object message in List)
  57. if (message is OperationOutput)
  58. return (OperationOutput) message;
  59. return null;
  60. }
  61. }
  62. #endregion // Properties
  63. #region Methods
  64. public int Add (OperationMessage operationMessage)
  65. {
  66. Insert (Count, operationMessage);
  67. return (Count - 1);
  68. }
  69. public bool Contains (OperationMessage operationMessage)
  70. {
  71. return List.Contains (operationMessage);
  72. }
  73. public void CopyTo (OperationMessage[] array, int index)
  74. {
  75. List.CopyTo (array, index);
  76. }
  77. public int IndexOf (OperationMessage operationMessage)
  78. {
  79. return List.IndexOf (operationMessage);
  80. }
  81. public void Insert (int index, OperationMessage operationMessage)
  82. {
  83. SetParent (operationMessage, operation);
  84. List.Insert (index, operationMessage);
  85. }
  86. protected override void OnInsert (int index, object value)
  87. {
  88. if (Count > 2 || value.GetType () == this [0].GetType ())
  89. throw new InvalidOperationException ("The operation object can only contain one input and one output message.");
  90. }
  91. protected override void OnSet (int index, object oldValue, object newValue)
  92. {
  93. if (oldValue.GetType () != newValue.GetType ())
  94. throw new InvalidOperationException ("The message types of the old and new value are not the same.");
  95. }
  96. protected override void OnValidate (object value)
  97. {
  98. if (value == null)
  99. throw new NullReferenceException ("The message object is a null reference.");
  100. if (!(value is OperationInput || value is OperationOutput))
  101. throw new ArgumentException ("The message object is not an input or an output message.");
  102. }
  103. public void Remove (OperationMessage operationMessage)
  104. {
  105. List.Remove (operationMessage);
  106. }
  107. protected override void SetParent (object value, object parent)
  108. {
  109. ((OperationMessage) value).SetParent ((Operation) parent);
  110. }
  111. #endregion // Methods
  112. }
  113. }