2 // System.Web.Services.Description.OperationMessageCollection.cs
\r
5 // Tim Coleman (tim@timcoleman.com)
\r
7 // Copyright (C) Tim Coleman, 2002
\r
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
31 using System.Web.Services;
\r
33 namespace System.Web.Services.Description {
\r
34 public sealed class OperationMessageCollection : ServiceDescriptionBaseCollection {
\r
36 #region Constructors
\r
38 internal OperationMessageCollection (Operation operation)
\r
43 #endregion // Constructors
\r
47 public OperationFlow Flow {
\r
51 if (this[0] is OperationInput)
\r
52 return OperationFlow.OneWay;
\r
54 return OperationFlow.Notification;
\r
56 if (this[0] is OperationInput)
\r
57 return OperationFlow.RequestResponse;
\r
59 return OperationFlow.SolicitResponse;
\r
61 return OperationFlow.None;
\r
65 public OperationInput Input {
\r
67 foreach (object message in List)
\r
68 if (message is OperationInput)
\r
69 return (OperationInput) message;
\r
74 public OperationMessage this [int index] {
\r
75 get { return (OperationMessage) List[index]; }
\r
76 set { List[index] = value; }
\r
79 public OperationOutput Output {
\r
81 foreach (object message in List)
\r
82 if (message is OperationOutput)
\r
83 return (OperationOutput) message;
\r
88 #endregion // Properties
\r
92 protected override string GetKey (object value)
\r
94 if (!(value is OperationMessage))
\r
95 throw new InvalidCastException ();
\r
96 return ((OperationMessage) value).Name;
\r
99 public int Add (OperationMessage operationMessage)
\r
101 Insert (Count, operationMessage);
\r
102 return (Count - 1);
\r
105 public bool Contains (OperationMessage operationMessage)
\r
107 return List.Contains (operationMessage);
\r
110 public void CopyTo (OperationMessage[] array, int index)
\r
112 List.CopyTo (array, index);
\r
115 public int IndexOf (OperationMessage operationMessage)
\r
117 return List.IndexOf (operationMessage);
\r
120 public void Insert (int index, OperationMessage operationMessage)
\r
122 List.Insert (index, operationMessage);
\r
125 protected override void OnInsert (int index, object value)
\r
130 if (Count == 1 && value.GetType() != this[0].GetType())
\r
133 throw new InvalidOperationException ("The operation object can only contain one input and one output message.");
\r
136 protected override void OnSet (int index, object oldValue, object newValue)
\r
138 if (oldValue.GetType () != newValue.GetType ())
\r
139 throw new InvalidOperationException ("The message types of the old and new value are not the same.");
\r
140 base.OnSet (index, oldValue, newValue);
\r
143 protected override void OnValidate (object value)
\r
146 throw new ArgumentException("The message object is a null reference.");
\r
147 if (!(value is OperationInput || value is OperationOutput))
\r
148 throw new ArgumentException ("The message object is not an input or an output message.");
\r
151 public void Remove (OperationMessage operationMessage)
\r
153 List.Remove (operationMessage);
\r
156 protected override void SetParent (object value, object parent)
\r
158 ((OperationMessage) value).SetParent ((Operation) parent);
\r
161 #endregion // Methods
\r