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;
31 private Uri actor = new Uri ("http://" + System.Net.Dns.GetHostName ());
33 private Microsoft.Web.Services.Timestamp.Timestamp timestamp;
34 private Microsoft.Web.Services.Security.Security security;
35 private Hashtable table;
36 private DimeAttachmentCollection attachments;
37 private string contentType;
38 private SecurityCollection extendedSecurity;
39 private ReferralCollection referrals;
41 private AddressingHeaders addressingHeaders;
42 private SoapChannel _channel;
43 private bool _processed = false;
44 private bool _isInbound = false;
46 internal SoapContext () : this (null)
50 internal SoapContext (SoapEnvelope env)
52 timestamp = new Microsoft.Web.Services.Timestamp.Timestamp ();
54 table = new Hashtable ();
58 addressingHeaders = new AddressingHeaders (env);
64 public Action Action {
65 get { return addressingHeaders.Action; }
66 set { addressingHeaders.Action = value; }
69 public ReplyTo ReplyTo {
70 get { return addressingHeaders.ReplyTo; }
71 set { addressingHeaders.ReplyTo = value; }
75 get { return addressingHeaders.To; }
78 public AddressingHeaders Addressing {
79 get { return addressingHeaders; }
80 set { addressingHeaders = value; }
83 public FaultTo FaultTo {
84 get { return addressingHeaders.FaultTo; }
85 set { addressingHeaders.FaultTo = value; }
89 get { return addressingHeaders.From; }
90 set { addressingHeaders.From = value; }
93 public MessageID MessageID {
94 get { return addressingHeaders.MessageID; }
95 set { addressingHeaders.MessageID = value; }
98 public Recipient Recipient {
99 get { return addressingHeaders.Recipient; }
100 set { addressingHeaders.Recipient = value; }
103 public RelatesTo RelatesTo {
104 get { return addressingHeaders.RelatesTo; }
105 set { addressingHeaders.RelatesTo = value; }
108 public SoapChannel Channel {
109 get { return _channel; }
110 set { _channel = value; }
113 public bool Processed {
114 get { return _processed; }
117 public void SetProcessed (bool to) {
121 public void SetTo (Uri uri) {
122 addressingHeaders.To = uri;
125 public void SetTo (To to) {
126 addressingHeaders.To = to;
129 public void SetActor (Uri act)
134 public void SetIsInbound (bool to)
140 get { return actor; }
143 public DimeAttachmentCollection Attachments {
145 if (attachments == null)
146 attachments = new DimeAttachmentCollection ();
151 public string ContentType {
152 get { return contentType; }
155 public SoapEnvelope Envelope {
156 get { return envelope; }
159 public SecurityCollection ExtendedSecurity {
160 get { return extendedSecurity; }
163 public object this [string key] {
164 get { return table [key]; }
167 throw new ArgumentNullException ("key");
177 public ReferralCollection Referrals {
178 get { return referrals; }
181 public Microsoft.Web.Services.Security.Security Security {
183 if (security == null) {
185 security = new Microsoft.Web.Services.Security.Security (actor.ToString ());
187 security = new Microsoft.Web.Services.Security.Security ();
193 public Microsoft.Web.Services.Timestamp.Timestamp Timestamp {
194 get { return timestamp; }
197 internal bool IsReserved (string key)
204 case "ExtendedSecurity":
206 case "IsIntermediary":
219 public void Add (string key, object value)
222 throw new ArgumentNullException ("key");
223 if (IsReserved (key))
224 throw new ArgumentException ("reserved key");
225 table.Add (key, value);
230 foreach (DictionaryEntry entry in table) {
231 string key = (string) entry.Key;
232 // remove all except reserved names
233 if (!IsReserved (key))
238 public bool Contains (string key)
241 throw new ArgumentNullException ("key");
242 return table.Contains (key);
245 public void CopyTo (SoapContext context)
248 throw new ArgumentNullException ("context");
249 context.actor = this.actor;
250 foreach (DimeAttachment da in Attachments) {
251 context.Attachments.Add (da);
253 context.contentType = contentType;
254 context.envelope = envelope;
255 context.extendedSecurity = ExtendedSecurity;
257 context.referrals = Referrals;
258 context.security = security;
259 context.timestamp = timestamp;
260 foreach (DictionaryEntry de in table) {
261 context.table.Add (de.Key, de.Value);
265 public IDictionaryEnumerator GetEnumerator ()
267 return table.GetEnumerator ();
270 public void Remove (string key)
273 throw new ArgumentNullException ("key");
274 if (IsReserved (key))
275 throw new ArgumentException ("reserved key");