2 // System.Web.Services.Protocols.SoapMessage.cs
\r
5 // Tim Coleman (tim@timcoleman.com)
\r
6 // Lluis Sanchez Gual (lluis@ximian.com)
\r
8 // Copyright (C) Tim Coleman, 2002
\r
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.
33 using System.Web.Services;
\r
35 namespace System.Web.Services.Protocols {
\r
36 public abstract class SoapMessage {
\r
40 string content_type = "text/xml";
\r
41 string content_encoding;
\r
42 SoapException exception = null;
\r
43 SoapHeaderCollection headers;
\r
44 SoapMessageStage stage;
\r
46 object[] inParameters;
\r
47 object[] outParameters;
\r
50 SoapProtocolVersion soapVersion;
\r
53 #endregion // Fields
\r
55 #region Constructors
\r
57 internal SoapMessage ()
\r
59 headers = new SoapHeaderCollection ();
\r
62 internal SoapMessage (Stream stream, SoapException exception)
\r
64 this.exception = exception;
\r
65 this.stream = stream;
\r
66 headers = new SoapHeaderCollection ();
\r
73 internal object[] InParameters
\r
75 get { return inParameters; }
\r
76 set { inParameters = value; }
\r
79 internal object[] OutParameters
\r
81 get { return outParameters; }
\r
82 set { outParameters = value; }
\r
85 public abstract string Action
\r
90 public string ContentType {
\r
91 get { return content_type; }
\r
92 set { content_type = value; }
\r
95 public SoapException Exception {
\r
96 get { return exception; }
\r
98 set { exception = value; }
\r
102 public SoapHeaderCollection Headers {
\r
103 get { return headers; }
\r
106 public abstract LogicalMethodInfo MethodInfo {
\r
110 public abstract bool OneWay {
\r
114 public SoapMessageStage Stage {
\r
115 get { return stage; }
\r
118 internal void SetStage (SoapMessageStage stage)
\r
120 this.stage = stage;
\r
123 public Stream Stream {
\r
129 public abstract string Url {
\r
134 public string ContentEncoding
\r
136 get { return content_encoding; }
\r
137 set { content_encoding = value; }
\r
140 internal string ContentEncoding
\r
142 get { return content_encoding; }
\r
143 set { content_encoding = value; }
\r
148 [System.Runtime.InteropServices.ComVisible(false)]
\r
149 public virtual SoapProtocolVersion SoapVersion {
\r
150 get { return soapVersion; }
\r
154 internal Stream InternalStream
\r
156 // for getter use public stream property
\r
162 #endregion Properties
\r
166 protected abstract void EnsureInStage ();
\r
167 protected abstract void EnsureOutStage ();
\r
169 protected void EnsureStage (SoapMessageStage stage)
\r
171 if ((((int) stage) & ((int) Stage)) == 0)
\r
172 throw new InvalidOperationException ("The current SoapMessageStage is not the asserted stage or stages.");
\r
175 public object GetInParameterValue (int index)
\r
177 return inParameters [index];
\r
180 public object GetOutParameterValue (int index)
\r
182 if (MethodInfo.IsVoid) return outParameters [index];
\r
183 else return outParameters [index + 1];
\r
186 public object GetReturnValue ()
\r
188 if (!MethodInfo.IsVoid && exception == null) return outParameters [0];
\r
192 internal void SetHeaders (SoapHeaderCollection headers)
\r
194 this.headers = headers;
\r
197 internal void SetException (SoapException ex)
\r
202 internal void CollectHeaders (object target, HeaderInfo[] headers, SoapHeaderDirection direction)
\r
205 foreach (HeaderInfo hi in headers)
\r
207 if ((hi.Direction & direction) != 0 && !hi.IsUnknownHeader)
\r
209 SoapHeader headerVal = hi.GetHeaderValue (target) as SoapHeader;
\r
210 if (headerVal != null)
\r
211 Headers.Add (headerVal);
\r
216 internal void UpdateHeaderValues (object target, HeaderInfo[] headersInfo)
\r
218 foreach (SoapHeader header in Headers)
\r
220 HeaderInfo hinfo = FindHeader (headersInfo, header.GetType ());
\r
221 if (hinfo != null) {
\r
222 hinfo.SetHeaderValue (target, header);
223 header.DidUnderstand = !hinfo.IsUnknownHeader;
228 HeaderInfo FindHeader (HeaderInfo[] headersInfo, Type headerType)
\r
230 HeaderInfo unknownHeaderInfo = null;
232 foreach (HeaderInfo headerInfo in headersInfo) {
233 if (headerInfo.HeaderType == headerType)
235 else if (headerInfo.IsUnknownHeader)
236 unknownHeaderInfo = headerInfo;
238 return unknownHeaderInfo;
241 #endregion // Methods
\r