**** Merged from MCS ****
[mono-project.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services / SoapContext.cs
blobd974a551cdbfdcdbafc6fe106a868799f18e0c47
1 //
2 // SoapContext.cs: SOAP Context
3 //
4 // Author:
5 // Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
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;
15 #if !WSE1
16 using Microsoft.Web.Services.Addressing;
17 using Microsoft.Web.Services.Messaging;
18 #endif
20 using System;
21 using System.Collections;
23 namespace Microsoft.Web.Services {
25 public sealed class SoapContext {
27 private SoapEnvelope envelope;
28 #if WSE1
29 private Uri actor;
30 private Microsoft.Web.Services.Timestamp.Timestamp timestamp;
31 #else
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 ();
34 #endif
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;
41 #if !WSE1
42 private AddressingHeaders addressingHeaders;
43 private SoapChannel _channel;
44 private bool _processed = false;
45 private bool _isInbound = false;
46 #endif
47 internal SoapContext () : this (null)
51 internal SoapContext (SoapEnvelope env)
53 timestamp = new Microsoft.Web.Services.Timestamp.Timestamp ();
54 #if WSE1
55 table = new Hashtable ();
57 envelope = env;
58 #else //WSE2
59 addressingHeaders = new AddressingHeaders (env);
61 envelope = env;
62 #endif
64 #if !WSE1
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; }
75 public To To {
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; }
89 public From From {
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) {
119 _processed = 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)
132 actor = act;
135 public void SetIsInbound (bool to)
137 _isInbound = to;
139 #endif
140 public Uri Actor {
141 get { return actor; }
144 public DimeAttachmentCollection Attachments {
145 get {
146 if (attachments == null)
147 attachments = new DimeAttachmentCollection ();
148 return attachments;
152 public string ContentType {
153 get { return contentType; }
156 public SoapEnvelope Envelope {
157 get { return envelope; }
160 public SecurityCollection ExtendedSecurity {
161 get {
162 if (extendedSecurity == null)
163 extendedSecurity = new SecurityCollection ();
164 return extendedSecurity;
168 public object this [string key] {
169 get { return table [key]; }
170 set {
171 if (key == null)
172 throw new ArgumentNullException ("key");
173 table [key] = value;
177 public Path Path {
178 get { return null; }
179 set {;}
182 public ReferralCollection Referrals {
183 get { return referrals; }
186 public Microsoft.Web.Services.Security.Security Security {
187 get {
188 if (security == null) {
189 if (actor != null)
190 security = new Microsoft.Web.Services.Security.Security (actor.ToString ());
191 else
192 security = new Microsoft.Web.Services.Security.Security ();
194 return security;
198 public Microsoft.Web.Services.Timestamp.Timestamp Timestamp {
199 get { return timestamp; }
202 internal bool IsReserved (string key)
204 switch (key) {
205 case "Actor":
206 case "Attachments":
207 case "ContentType":
208 case "Envelope":
209 case "ExtendedSecurity":
210 case "IsInbound":
211 case "IsIntermediary":
212 case "Referrals":
213 case "Path":
214 case "Security":
215 case "Timestamp":
216 case "WebRequest":
217 case "WebResponse":
218 return true;
219 default:
220 return false;
224 public void Add (string key, object value)
226 if (key == null)
227 throw new ArgumentNullException ("key");
228 if (IsReserved (key))
229 throw new ArgumentException ("reserved key");
230 table.Add (key, value);
233 public void Clear ()
235 foreach (DictionaryEntry entry in table) {
236 string key = (string) entry.Key;
237 // remove all except reserved names
238 if (!IsReserved (key))
239 table.Remove (key);
243 public bool Contains (string key)
245 if (key == null)
246 throw new ArgumentNullException ("key");
247 return table.Contains (key);
250 public void CopyTo (SoapContext context)
252 if (context == null)
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;
261 context.Path = Path;
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)
277 if (key == null)
278 throw new ArgumentNullException ("key");
279 if (IsReserved (key))
280 throw new ArgumentException ("reserved key");
281 table.Remove (key);