**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web.Services / System.Web.Services.Protocols / SoapMessage.cs
blob791934a4556c192d0dbbac21389b55d66c3d2376
1 //
2 // System.Web.Services.Protocols.SoapMessage.cs
3 //
4 // Author:
5 // Tim Coleman (tim@timcoleman.com)
6 // Lluis Sanchez Gual (lluis@ximian.com)
7 //
8 // Copyright (C) Tim Coleman, 2002
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.IO;
33 using System.Web.Services;
35 namespace System.Web.Services.Protocols {
36 public abstract class SoapMessage {
38 #region Fields
40 string content_type = "text/xml";
41 string content_encoding;
42 SoapException exception = null;
43 SoapHeaderCollection headers;
44 SoapMessageStage stage;
45 Stream stream;
46 object[] inParameters;
47 object[] outParameters;
49 #if NET_2_0
50 SoapProtocolVersion soapVersion;
51 #endif
53 #endregion // Fields
55 #region Constructors
57 internal SoapMessage ()
59 headers = new SoapHeaderCollection ();
62 internal SoapMessage (Stream stream)
64 this.stream = stream;
67 internal SoapMessage (Stream stream, SoapException exception)
69 this.exception = exception;
70 this.stream = stream;
71 headers = new SoapHeaderCollection ();
74 #endregion
76 #region Properties
78 internal object[] InParameters
80 get { return inParameters; }
81 set { inParameters = value; }
84 internal object[] OutParameters
86 get { return outParameters; }
87 set { outParameters = value; }
90 public abstract string Action
92 get;
95 public string ContentType {
96 get { return content_type; }
97 set { content_type = value; }
100 public SoapException Exception {
101 get { return exception; }
102 #if NET_2_0
103 set { exception = value; }
104 #endif
107 public SoapHeaderCollection Headers {
108 get { return headers; }
111 public abstract LogicalMethodInfo MethodInfo {
112 get;
115 public abstract bool OneWay {
116 get;
119 public SoapMessageStage Stage {
120 get { return stage; }
123 internal void SetStage (SoapMessageStage stage)
125 this.stage = stage;
128 public Stream Stream {
129 get {
130 return stream;
134 public abstract string Url {
135 get;
138 #if NET_1_1
139 public string ContentEncoding
141 get { return content_encoding; }
142 set { content_encoding = value; }
144 #else
145 internal string ContentEncoding
147 get { return content_encoding; }
148 set { content_encoding = value; }
150 #endif
152 #if NET_2_0
153 [System.Runtime.InteropServices.ComVisible(false)]
154 public virtual SoapProtocolVersion SoapVersion {
155 get { return soapVersion; }
157 #endif
159 #endregion Properties
161 #region Methods
163 protected abstract void EnsureInStage ();
164 protected abstract void EnsureOutStage ();
166 protected void EnsureStage (SoapMessageStage stage)
168 if ((((int) stage) & ((int) Stage)) == 0)
169 throw new InvalidOperationException ("The current SoapMessageStage is not the asserted stage or stages.");
172 public object GetInParameterValue (int index)
174 return inParameters [index];
177 public object GetOutParameterValue (int index)
179 if (MethodInfo.IsVoid) return outParameters [index];
180 else return outParameters [index + 1];
183 public object GetReturnValue ()
185 if (!MethodInfo.IsVoid && exception == null) return outParameters [0];
186 else return null;
189 internal void SetHeaders (SoapHeaderCollection headers)
191 this.headers = headers;
194 internal void SetException (SoapException ex)
196 exception = ex;
199 internal void CollectHeaders (object target, HeaderInfo[] headers, SoapHeaderDirection direction)
201 Headers.Clear ();
202 foreach (HeaderInfo hi in headers)
204 if ((hi.Direction & direction) != 0 && !hi.IsUnknownHeader)
206 SoapHeader headerVal = hi.GetHeaderValue (target) as SoapHeader;
207 if (headerVal != null)
208 Headers.Add (headerVal);
213 internal void UpdateHeaderValues (object target, HeaderInfo[] headersInfo)
215 foreach (SoapHeader header in Headers)
217 HeaderInfo hinfo = FindHeader (headersInfo, header.GetType ());
218 if (hinfo != null) {
219 hinfo.SetHeaderValue (target, header);
220 header.DidUnderstand = !hinfo.IsUnknownHeader;
225 HeaderInfo FindHeader (HeaderInfo[] headersInfo, Type headerType)
227 HeaderInfo unknownHeaderInfo = null;
229 foreach (HeaderInfo headerInfo in headersInfo) {
230 if (headerInfo.HeaderType == headerType)
231 return headerInfo;
232 else if (headerInfo.IsUnknownHeader)
233 unknownHeaderInfo = headerInfo;
235 return unknownHeaderInfo;
238 #endregion // Methods