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.
33 using System
.Web
.Services
;
35 namespace System
.Web
.Services
.Protocols
{
36 public abstract class SoapMessage
{
40 string content_type
= "text/xml";
41 string content_encoding
;
42 SoapException exception
= null;
43 SoapHeaderCollection headers
;
44 SoapMessageStage stage
;
46 object[] inParameters
;
47 object[] outParameters
;
50 SoapProtocolVersion soapVersion
;
57 internal SoapMessage ()
59 headers
= new SoapHeaderCollection ();
62 internal SoapMessage (Stream stream
)
67 internal SoapMessage (Stream stream
, SoapException exception
)
69 this.exception
= exception
;
71 headers
= new SoapHeaderCollection ();
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
95 public string ContentType
{
96 get { return content_type; }
97 set { content_type = value; }
100 public SoapException Exception
{
101 get { return exception; }
103 set { exception = value; }
107 public SoapHeaderCollection Headers
{
108 get { return headers; }
111 public abstract LogicalMethodInfo MethodInfo
{
115 public abstract bool OneWay
{
119 public SoapMessageStage Stage
{
120 get { return stage; }
123 internal void SetStage (SoapMessageStage stage
)
128 public Stream Stream
{
134 public abstract string Url
{
139 public string ContentEncoding
141 get { return content_encoding; }
142 set { content_encoding = value; }
145 internal string ContentEncoding
147 get { return content_encoding; }
148 set { content_encoding = value; }
153 [System
.Runtime
.InteropServices
.ComVisible(false)]
154 public virtual SoapProtocolVersion SoapVersion
{
155 get { return soapVersion; }
159 #endregion Properties
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];
189 internal void SetHeaders (SoapHeaderCollection headers
)
191 this.headers
= headers
;
194 internal void SetException (SoapException ex
)
199 internal void CollectHeaders (object target
, HeaderInfo
[] headers
, SoapHeaderDirection direction
)
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 ());
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
)
232 else if (headerInfo
.IsUnknownHeader
)
233 unknownHeaderInfo
= headerInfo
;
235 return unknownHeaderInfo
;
238 #endregion // Methods