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 HeaderInfo
= System
.Web
.Services
.Protocols
.SoapHeaderMapping
;
34 using System
.ComponentModel
;
36 using System
.Web
.Services
;
38 namespace System
.Web
.Services
.Protocols
{
39 public abstract class SoapMessage
{
43 string content_type
= "text/xml";
44 string content_encoding
;
45 SoapException exception
= null;
46 SoapHeaderCollection headers
;
47 SoapMessageStage stage
;
49 object[] inParameters
;
50 object[] outParameters
;
53 SoapProtocolVersion soapVersion
;
60 internal SoapMessage ()
62 headers
= new SoapHeaderCollection ();
65 internal SoapMessage (Stream stream
, SoapException exception
)
67 this.exception
= exception
;
69 headers
= new SoapHeaderCollection ();
76 internal object[] InParameters
78 get { return inParameters; }
79 set { inParameters = value; }
82 internal object[] OutParameters
84 get { return outParameters; }
85 set { outParameters = value; }
88 public abstract string Action
93 public string ContentType
{
94 get { return content_type; }
95 set { content_type = value; }
98 public SoapException Exception
{
99 get { return exception; }
101 set { exception = value; }
105 public SoapHeaderCollection Headers
{
106 get { return headers; }
109 public abstract LogicalMethodInfo MethodInfo
{
113 public abstract bool OneWay
{
117 public SoapMessageStage Stage
{
118 get { return stage; }
121 internal void SetStage (SoapMessageStage stage
)
126 public Stream Stream
{
132 public abstract string Url
{
137 public string ContentEncoding
139 get { return content_encoding; }
140 set { content_encoding = value; }
143 internal string ContentEncoding
145 get { return content_encoding; }
146 set { content_encoding = value; }
150 internal bool IsSoap12
{
153 return SoapVersion
== SoapProtocolVersion
.Soap12
;
161 [System
.Runtime
.InteropServices
.ComVisible(false)]
162 [DefaultValue (SoapProtocolVersion
.Default
)]
163 public virtual SoapProtocolVersion SoapVersion
{
164 get { return soapVersion; }
168 internal Stream InternalStream
170 // for getter use public stream property
176 #endregion Properties
180 protected abstract void EnsureInStage ();
181 protected abstract void EnsureOutStage ();
183 protected void EnsureStage (SoapMessageStage stage
)
185 if ((((int) stage
) & ((int) Stage
)) == 0)
186 throw new InvalidOperationException ("The current SoapMessageStage is not the asserted stage or stages.");
189 public object GetInParameterValue (int index
)
191 return inParameters
[index
];
194 public object GetOutParameterValue (int index
)
196 if (MethodInfo
.IsVoid
) return outParameters
[index
];
197 else return outParameters
[index
+ 1];
200 public object GetReturnValue ()
202 if (!MethodInfo
.IsVoid
&& exception
== null) return outParameters
[0];
206 internal void SetHeaders (SoapHeaderCollection headers
)
208 this.headers
= headers
;
211 internal void SetException (SoapException ex
)
216 internal void CollectHeaders (object target
, HeaderInfo
[] headers
, SoapHeaderDirection direction
)
219 foreach (HeaderInfo hi
in headers
)
221 if ((hi
.Direction
& direction
) != 0 && !hi
.Custom
)
223 SoapHeader headerVal
= hi
.GetHeaderValue (target
) as SoapHeader
;
224 if (headerVal
!= null)
225 Headers
.Add (headerVal
);
230 internal void UpdateHeaderValues (object target
, HeaderInfo
[] headersInfo
)
232 foreach (SoapHeader header
in Headers
)
234 HeaderInfo hinfo
= FindHeader (headersInfo
, header
.GetType ());
236 hinfo
.SetHeaderValue (target
, header
);
237 header
.DidUnderstand
= !hinfo
.Custom
;
242 HeaderInfo
FindHeader (HeaderInfo
[] headersInfo
, Type headerType
)
244 HeaderInfo unknownHeaderInfo
= null;
246 foreach (HeaderInfo headerInfo
in headersInfo
) {
247 if (headerInfo
.HeaderType
== headerType
)
249 else if (headerInfo
.Custom
)
250 unknownHeaderInfo
= headerInfo
;
252 return unknownHeaderInfo
;
255 #endregion // Methods