2 // SoapContext.cs: SOAP Context
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
10 using Microsoft
.Web
.Services
.Dime
;
11 using Microsoft
.Web
.Services
.Referral
;
12 using Microsoft
.Web
.Services
.Routing
;
13 using Microsoft
.Web
.Services
.Security
;
14 using Microsoft
.Web
.Services
.Timestamp
;
16 using Microsoft
.Web
.Services
.Addressing
;
17 using Microsoft
.Web
.Services
.Messaging
;
21 using System
.Collections
;
23 namespace Microsoft
.Web
.Services
{
25 public sealed class SoapContext
{
27 private SoapEnvelope envelope
;
30 private Microsoft
.Web
.Services
.Timestamp
.Timestamp timestamp
;
32 private Uri actor
= new Uri ("http://" + System
.Net
.Dns
.GetHostName ());
33 private Microsoft
.Web
.Services
.Timestamp
.Timestamp timestamp
= new Microsoft
.Web
.Services
.Timestamp
.Timestamp ();
35 private Microsoft
.Web
.Services
.Security
.Security security
;
36 private Hashtable table
;
37 private DimeAttachmentCollection attachments
;
38 private string contentType
;
39 private SecurityCollection extendedSecurity
;
40 private ReferralCollection referrals
;
42 private AddressingHeaders addressingHeaders
;
43 private SoapChannel _channel
;
44 private bool _processed
= false;
45 private bool _isInbound
= false;
47 internal SoapContext () : this (null)
51 internal SoapContext (SoapEnvelope env
)
53 timestamp
= new Microsoft
.Web
.Services
.Timestamp
.Timestamp ();
55 table
= new Hashtable ();
59 addressingHeaders
= new AddressingHeaders (env
);
65 public Action Action
{
66 get { return addressingHeaders.Action; }
67 set { addressingHeaders.Action = value; }
70 public ReplyTo ReplyTo
{
71 get { return addressingHeaders.ReplyTo; }
72 set { addressingHeaders.ReplyTo = value; }
76 get { return addressingHeaders.To; }
79 public AddressingHeaders Addressing
{
80 get { return addressingHeaders; }
81 set { addressingHeaders = value; }
84 public FaultTo FaultTo
{
85 get { return addressingHeaders.FaultTo; }
86 set { addressingHeaders.FaultTo = value; }
90 get { return addressingHeaders.From; }
91 set { addressingHeaders.From = value; }
94 public MessageID MessageID
{
95 get { return addressingHeaders.MessageID; }
96 set { addressingHeaders.MessageID = value; }
99 public Recipient Recipient
{
100 get { return addressingHeaders.Recipient; }
101 set { addressingHeaders.Recipient = value; }
104 public RelatesTo RelatesTo
{
105 get { return addressingHeaders.RelatesTo; }
106 set { addressingHeaders.RelatesTo = value; }
109 public SoapChannel Channel
{
110 get { return _channel; }
111 set { _channel = value; }
114 public bool Processed
{
115 get { return _processed; }
118 public void SetProcessed (bool to
) {
122 public void SetTo (Uri uri
) {
123 addressingHeaders
.To
= uri
;
126 public void SetTo (To to
) {
127 addressingHeaders
.To
= to
;
130 public void SetActor (Uri act
)
135 public void SetIsInbound (bool to
)
141 get { return actor; }
144 public DimeAttachmentCollection Attachments
{
146 if (attachments
== null)
147 attachments
= new DimeAttachmentCollection ();
152 public string ContentType
{
153 get { return contentType; }
156 public SoapEnvelope Envelope
{
157 get { return envelope; }
160 public SecurityCollection ExtendedSecurity
{
162 if (extendedSecurity
== null)
163 extendedSecurity
= new SecurityCollection ();
164 return extendedSecurity
;
168 public object this [string key
] {
169 get { return table [key]; }
172 throw new ArgumentNullException ("key");
182 public ReferralCollection Referrals
{
183 get { return referrals; }
186 public Microsoft
.Web
.Services
.Security
.Security Security
{
188 if (security
== null) {
190 security
= new Microsoft
.Web
.Services
.Security
.Security (actor
.ToString ());
192 security
= new Microsoft
.Web
.Services
.Security
.Security ();
198 public Microsoft
.Web
.Services
.Timestamp
.Timestamp Timestamp
{
199 get { return timestamp; }
202 internal bool IsReserved (string key
)
209 case "ExtendedSecurity":
211 case "IsIntermediary":
224 public void Add (string key
, object value)
227 throw new ArgumentNullException ("key");
228 if (IsReserved (key
))
229 throw new ArgumentException ("reserved key");
230 table
.Add (key
, value);
235 foreach (DictionaryEntry entry
in table
) {
236 string key
= (string) entry
.Key
;
237 // remove all except reserved names
238 if (!IsReserved (key
))
243 public bool Contains (string key
)
246 throw new ArgumentNullException ("key");
247 return table
.Contains (key
);
250 public void CopyTo (SoapContext context
)
253 throw new ArgumentNullException ("context");
254 context
.actor
= this.actor
;
255 foreach (DimeAttachment da
in Attachments
) {
256 context
.Attachments
.Add (da
);
258 context
.contentType
= contentType
;
259 context
.envelope
= envelope
;
260 context
.extendedSecurity
= ExtendedSecurity
;
262 context
.referrals
= Referrals
;
263 context
.security
= security
;
264 context
.timestamp
= timestamp
;
265 foreach (DictionaryEntry de
in table
) {
266 context
.table
.Add (de
.Key
, de
.Value
);
270 public IDictionaryEnumerator
GetEnumerator ()
272 return table
.GetEnumerator ();
275 public void Remove (string key
)
278 throw new ArgumentNullException ("key");
279 if (IsReserved (key
))
280 throw new ArgumentException ("reserved key");