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 internal OperationFault Fault {
\r
90 foreach (object message in List)
\r
91 if (message is OperationFault)
\r
92 return (OperationFault) message;
\r
97 #endregion // Properties
\r
101 protected override string GetKey (object value)
\r
103 if (!(value is OperationMessage))
\r
104 throw new InvalidCastException ();
\r
105 return ((OperationMessage) value).Name;
\r
108 public int Add (OperationMessage operationMessage)
\r
110 Insert (Count, operationMessage);
\r
111 return (Count - 1);
\r
114 public bool Contains (OperationMessage operationMessage)
\r
116 return List.Contains (operationMessage);
\r
119 public void CopyTo (OperationMessage[] array, int index)
\r
121 List.CopyTo (array, index);
\r
124 public int IndexOf (OperationMessage operationMessage)
\r
126 return List.IndexOf (operationMessage);
\r
129 public void Insert (int index, OperationMessage operationMessage)
\r
131 List.Insert (index, operationMessage);
\r
134 protected override void OnInsert (int index, object value)
\r
139 if (Count == 1 && value.GetType() != this[0].GetType())
\r
142 throw new InvalidOperationException ("The operation object can only contain one input and one output message.");
\r
145 protected override void OnSet (int index, object oldValue, object newValue)
\r
147 if (oldValue.GetType () != newValue.GetType ())
\r
148 throw new InvalidOperationException ("The message types of the old and new value are not the same.");
\r
149 base.OnSet (index, oldValue, newValue);
\r
152 protected override void OnValidate (object value)
\r
155 throw new ArgumentException("The message object is a null reference.");
\r
156 if (!(value is OperationInput || value is OperationOutput))
\r
157 throw new ArgumentException ("The message object is not an input or an output message.");
\r
160 public void Remove (OperationMessage operationMessage)
\r
162 List.Remove (operationMessage);
\r
165 protected override void SetParent (object value, object parent)
\r
167 ((OperationMessage) value).SetParent ((Operation) parent);
\r
170 #endregion // Methods
\r