2 // System.Web.Services.Protocols.SoapMessage.cs
5 // Tim Coleman (tim@timcoleman.com)
6 // Lluis Sanchez Gual (lluis@ximian.com)
8 // Copyright (C) Tim Coleman, 2002
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.ComponentModel;
34 using System.Web.Services;
36 namespace System.Web.Services.Protocols {
37 public abstract class SoapMessage {
41 string content_type = "text/xml";
42 string content_encoding;
43 SoapException exception = null;
44 SoapHeaderCollection headers;
45 SoapMessageStage stage;
47 object[] inParameters;
48 object[] outParameters;
51 SoapProtocolVersion soapVersion;
58 internal SoapMessage ()
60 headers = new SoapHeaderCollection ();
63 internal SoapMessage (Stream stream, SoapException exception)
65 this.exception = exception;
67 headers = new SoapHeaderCollection ();
74 internal object[] InParameters
76 get { return inParameters; }
77 set { inParameters = value; }
80 internal object[] OutParameters
82 get { return outParameters; }
83 set { outParameters = value; }
86 public abstract string Action
91 public string ContentType {
92 get { return content_type; }
93 set { content_type = value; }
96 public SoapException Exception {
97 get { return exception; }
99 set { exception = value; }
103 public SoapHeaderCollection Headers {
104 get { return headers; }
107 public abstract LogicalMethodInfo MethodInfo {
111 public abstract bool OneWay {
115 public SoapMessageStage Stage {
116 get { return stage; }
119 internal void SetStage (SoapMessageStage stage)
124 public Stream Stream {
130 public abstract string Url {
135 public string ContentEncoding
137 get { return content_encoding; }
138 set { content_encoding = value; }
141 internal string ContentEncoding
143 get { return content_encoding; }
144 set { content_encoding = value; }
149 [System.Runtime.InteropServices.ComVisible(false)]
150 [DefaultValue (SoapProtocolVersion.Default)]
151 public virtual SoapProtocolVersion SoapVersion {
152 get { return soapVersion; }
156 internal Stream InternalStream
158 // for getter use public stream property
164 #endregion Properties
168 protected abstract void EnsureInStage ();
169 protected abstract void EnsureOutStage ();
171 protected void EnsureStage (SoapMessageStage stage)
173 if ((((int) stage) & ((int) Stage)) == 0)
174 throw new InvalidOperationException ("The current SoapMessageStage is not the asserted stage or stages.");
177 public object GetInParameterValue (int index)
179 return inParameters [index];
182 public object GetOutParameterValue (int index)
184 if (MethodInfo.IsVoid) return outParameters [index];
185 else return outParameters [index + 1];
188 public object GetReturnValue ()
190 if (!MethodInfo.IsVoid && exception == null) return outParameters [0];
194 internal void SetHeaders (SoapHeaderCollection headers)
196 this.headers = headers;
199 internal void SetException (SoapException ex)
204 internal void CollectHeaders (object target, HeaderInfo[] headers, SoapHeaderDirection direction)
207 foreach (HeaderInfo hi in headers)
209 if ((hi.Direction & direction) != 0 && !hi.IsUnknownHeader)
211 SoapHeader headerVal = hi.GetHeaderValue (target) as SoapHeader;
212 if (headerVal != null)
213 Headers.Add (headerVal);
218 internal void UpdateHeaderValues (object target, HeaderInfo[] headersInfo)
220 foreach (SoapHeader header in Headers)
222 HeaderInfo hinfo = FindHeader (headersInfo, header.GetType ());
224 hinfo.SetHeaderValue (target, header);
225 header.DidUnderstand = !hinfo.IsUnknownHeader;
230 HeaderInfo FindHeader (HeaderInfo[] headersInfo, Type headerType)
232 HeaderInfo unknownHeaderInfo = null;
234 foreach (HeaderInfo headerInfo in headersInfo) {
235 if (headerInfo.HeaderType == headerType)
237 else if (headerInfo.IsUnknownHeader)
238 unknownHeaderInfo = headerInfo;
240 return unknownHeaderInfo;
243 #endregion // Methods