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
;
52 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; }
98 set { exception = value; }
101 public SoapHeaderCollection Headers
{
102 get { return headers; }
105 public abstract LogicalMethodInfo MethodInfo
{
109 public abstract bool OneWay
{
113 public SoapMessageStage Stage
{
114 get { return stage; }
117 internal void SetStage (SoapMessageStage stage
)
122 public Stream Stream
{
128 public abstract string Url
{
132 public string ContentEncoding
134 get { return content_encoding; }
135 set { content_encoding = value; }
138 internal bool IsSoap12
{
140 return SoapVersion
== SoapProtocolVersion
.Soap12
;
144 [System
.Runtime
.InteropServices
.ComVisible(false)]
145 [DefaultValue (SoapProtocolVersion
.Default
)]
146 public virtual SoapProtocolVersion SoapVersion
{
147 get { return soapVersion; }
150 internal Stream InternalStream
152 // for getter use public stream property
158 #endregion Properties
162 protected abstract void EnsureInStage ();
163 protected abstract void EnsureOutStage ();
165 protected void EnsureStage (SoapMessageStage stage
)
167 if ((((int) stage
) & ((int) Stage
)) == 0)
168 throw new InvalidOperationException ("The current SoapMessageStage is not the asserted stage or stages.");
171 public object GetInParameterValue (int index
)
173 return inParameters
[index
];
176 public object GetOutParameterValue (int index
)
178 if (MethodInfo
.IsVoid
) return outParameters
[index
];
179 else return outParameters
[index
+ 1];
182 public object GetReturnValue ()
184 if (!MethodInfo
.IsVoid
&& exception
== null) return outParameters
[0];
188 internal void SetHeaders (SoapHeaderCollection headers
)
190 this.headers
= headers
;
193 internal void SetException (SoapException ex
)
198 internal void CollectHeaders (object target
, HeaderInfo
[] headers
, SoapHeaderDirection direction
)
201 foreach (HeaderInfo hi
in headers
)
203 if ((hi
.Direction
& direction
) != 0 && !hi
.Custom
)
205 SoapHeader headerVal
= hi
.GetHeaderValue (target
) as SoapHeader
;
206 if (headerVal
!= null)
207 Headers
.Add (headerVal
);
212 internal void UpdateHeaderValues (object target
, HeaderInfo
[] headersInfo
)
214 foreach (SoapHeader header
in Headers
)
216 HeaderInfo hinfo
= FindHeader (headersInfo
, header
.GetType ());
218 hinfo
.SetHeaderValue (target
, header
);
219 header
.DidUnderstand
= !hinfo
.Custom
;
224 HeaderInfo
FindHeader (HeaderInfo
[] headersInfo
, Type headerType
)
226 HeaderInfo unknownHeaderInfo
= null;
228 foreach (HeaderInfo headerInfo
in headersInfo
) {
229 if (headerInfo
.HeaderType
== headerType
)
231 else if (headerInfo
.Custom
)
232 unknownHeaderInfo
= headerInfo
;
234 return unknownHeaderInfo
;
237 #endregion // Methods