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
>
40 static OperationContext current
;
42 public static OperationContext Current
{
43 get { return current; }
44 set { current = value; }
47 Message incoming_message
;
49 EndpointDispatcher dispatcher
;
51 IContextChannel channel
;
52 RequestContext request_ctx
;
53 ExtensionCollection
<OperationContext
> extensions
;
54 MessageHeaders outgoing_headers
;
55 MessageProperties outgoing_properties
;
56 InstanceContext instance_context
;
58 public OperationContext (IContextChannel channel
)
59 : this (channel
, true)
63 internal OperationContext (IContextChannel channel
, bool isUserContext
)
66 throw new ArgumentNullException ("channel");
67 this.channel
= channel
;
68 IsUserContext
= isUserContext
;
71 public event EventHandler OperationCompleted
;
73 public IContextChannel Channel
{
74 get { return channel; }
77 public IExtensionCollection
<OperationContext
> Extensions
{
79 if (extensions
== null)
80 extensions
= new ExtensionCollection
<OperationContext
> (this);
87 public EndpointDispatcher EndpointDispatcher
{
88 get { return dispatcher; }
89 set { dispatcher = value; }
91 public bool HasSupportingTokens
{
92 get { return SupportingTokens != null ? SupportingTokens.Count > 0 : false; }
95 public ServiceHostBase Host
{
96 get { return dispatcher != null ? dispatcher.ChannelDispatcher.Host : null; }
100 public MessageHeaders IncomingMessageHeaders
{
101 get { return incoming_message != null ? incoming_message.Headers : null; }
104 public MessageProperties IncomingMessageProperties
{
105 get { return incoming_message != null ? incoming_message.Properties : null; }
108 public MessageVersion IncomingMessageVersion
{
109 get { return incoming_message != null ? incoming_message.Version : null; }
113 public InstanceContext InstanceContext
{
115 return instance_context
;
118 instance_context
= value;
122 public bool IsUserContext { get; private set; }
124 public MessageHeaders OutgoingMessageHeaders
{
126 if (outgoing_headers
== null)
127 outgoing_headers
= new MessageHeaders (MessageVersion
.Default
);
128 return outgoing_headers
;
132 public MessageProperties OutgoingMessageProperties
{
134 if (outgoing_properties
== null)
135 outgoing_properties
= new MessageProperties ();
136 return outgoing_properties
;
140 public RequestContext RequestContext
{
141 get { return request_ctx; }
142 set { request_ctx = value; }
145 public string SessionId
{
146 get { return Channel.SessionId; }
150 public ServiceSecurityContext ServiceSecurityContext
{
151 get { return IncomingMessageProperties != null ? IncomingMessageProperties.Security.ServiceSecurityContext : null; }
154 public ICollection
<SupportingTokenSpecification
> SupportingTokens
{
155 get { return IncomingMessageProperties != null ? IncomingMessageProperties.Security.IncomingSupportingTokens : null; }
158 public T GetCallbackChannel
<T
> ()
160 // It is correct; OperationContext.Channel and OperationContext.GetCallbackChannel<T>() returns the same instance on .NET. (at least as far as I tested.)
161 return (T
) (object) channel
;
165 public void SetTransactionComplete ()
167 throw new NotImplementedException ();
171 internal Message IncomingMessage
{
173 return incoming_message
;
176 incoming_message
= value;