4 // Author: Atsushi Enomoto (atsushi@ximian.com)
6 // Copyright (C) 2005,2007 Novell, Inc (http://www.novell.com)
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 using System.Collections.Generic;
29 using System.Collections.ObjectModel;
30 using System.ServiceModel.Channels;
31 using System.ServiceModel.Dispatcher;
32 using System.ServiceModel.Security;
33 using System.Threading;
35 namespace System.ServiceModel
37 public sealed class OperationContext : IExtensibleObject<OperationContext>
39 // generated guid (no special meaning)
40 const string operation_context_name = "c15795e2-bb44-4cfb-a89c-8529feb170cb";
41 Message incoming_message;
42 IDefaultCommunicationTimeouts timeouts;
44 public static OperationContext Current {
45 get { return Thread.GetData (Thread.GetNamedDataSlot (operation_context_name)) as OperationContext; }
46 set { Thread.SetData (Thread.GetNamedDataSlot (operation_context_name), value); }
49 EndpointDispatcher dispatcher;
50 IContextChannel channel;
51 RequestContext request_ctx;
52 ExtensionCollection<OperationContext> extensions;
53 MessageHeaders outgoing_headers;
54 MessageProperties outgoing_properties;
55 InstanceContext instance_context;
57 public OperationContext (IContextChannel channel)
60 throw new ArgumentNullException ("channel");
61 this.channel = channel;
64 public event EventHandler OperationCompleted;
66 public IContextChannel Channel {
67 get { return channel; }
70 public EndpointDispatcher EndpointDispatcher {
71 get { return dispatcher; }
72 set { dispatcher = value; }
75 public IExtensionCollection<OperationContext> Extensions {
77 if (extensions == null)
78 extensions = new ExtensionCollection<OperationContext> (this);
83 public bool HasSupportingTokens {
84 get { return SupportingTokens != null ? SupportingTokens.Count > 0 : false; }
87 public ServiceHostBase Host {
88 get { return dispatcher != null ? dispatcher.ChannelDispatcher.Host : null; }
91 public MessageHeaders IncomingMessageHeaders {
92 get { return request_ctx != null ? request_ctx.RequestMessage.Headers : null; }
95 public MessageProperties IncomingMessageProperties {
96 get { return request_ctx != null ? request_ctx.RequestMessage.Properties : null; }
99 public MessageVersion IncomingMessageVersion {
100 get { return request_ctx != null ? request_ctx.RequestMessage.Version : null; }
104 public InstanceContext InstanceContext {
106 return instance_context;
109 instance_context = value;
114 public bool IsUserContext {
115 get { throw new NotImplementedException (); }
118 public MessageHeaders OutgoingMessageHeaders {
120 if (outgoing_headers == null)
121 outgoing_headers = new MessageHeaders (MessageVersion.Default);
122 return outgoing_headers;
126 public MessageProperties OutgoingMessageProperties {
128 if (outgoing_properties == null)
129 outgoing_properties = new MessageProperties ();
130 return outgoing_properties;
134 public RequestContext RequestContext {
135 get { return request_ctx; }
136 set { request_ctx = value; }
139 public ServiceSecurityContext ServiceSecurityContext {
140 get { return IncomingMessageProperties != null ? IncomingMessageProperties.Security.ServiceSecurityContext : null; }
144 public string SessionId {
145 get { throw new NotImplementedException (); }
148 public ICollection<SupportingTokenSpecification> SupportingTokens {
149 get { return IncomingMessageProperties != null ? IncomingMessageProperties.Security.IncomingSupportingTokens : null; }
152 public T GetCallbackChannel<T> ()
154 if (!(channel is IDuplexContextChannel))
156 IDuplexContextChannel duplex = (IDuplexContextChannel) channel;
157 foreach (IChannel ch in duplex.CallbackInstance.IncomingChannels)
158 if (typeof (T).IsAssignableFrom (ch.GetType ()))
159 return (T) (object) ch;
160 foreach (IChannel ch in duplex.CallbackInstance.OutgoingChannels)
161 if (typeof (T).IsAssignableFrom (ch.GetType ()))
162 return (T) (object) ch;
167 public void SetTransactionComplete ()
169 throw new NotImplementedException ();
172 internal Message IncomingMessage {
174 return incoming_message;
177 incoming_message = value;
181 internal IDefaultCommunicationTimeouts CommunicationTimeouts