OperationContext Class
Provides access to the execution context of a service method.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
The OperationContext type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | OperationContext | Initializes a new instance of the OperationContext class that uses the specified IContextChannel in a client application. |
| Name | Description | |
|---|---|---|
![]() | Channel | Gets the channel associated with the current OperationContext object. |
![]() ![]() ![]() | Current | Gets or sets the execution context for the current thread. |
![]() | EndpointDispatcher | Gets or sets the endpoint dispatcher for the endpoint to inspect or modify. |
![]() | Extensions | Gets the collection of service extensions from the current message context. |
![]() | HasSupportingTokens | Gets a value that indicates whether the incoming message has supporting tokens. |
![]() | Host | Gets the ServiceHost for the current service object. |
![]() ![]() | IncomingMessageHeaders | Gets the incoming message headers for the OperationContext. |
![]() ![]() | IncomingMessageProperties | Gets the message properties for the incoming message in the OperationContext. |
![]() ![]() | IncomingMessageVersion | Gets the incoming SOAP message version for the OperationContext. |
![]() | InstanceContext | Gets the InstanceContext object that manages the current service instance. |
![]() ![]() | IsUserContext | This property is intended for system use and should not be called by users. |
![]() ![]() | OutgoingMessageHeaders | Gets the outgoing message headers for the active OperationContext. |
![]() ![]() | OutgoingMessageProperties | Gets the message properties for the outbound message in the active OperationContext. |
![]() ![]() | RequestContext | Gets or sets the RequestContext implementation for this method. |
![]() | ServiceSecurityContext | Gets or sets the ServiceSecurityContext within which this method executes. |
![]() | SessionId | Gets the String used to identify the current session. |
![]() | SupportingTokens | Gets a ICollection<T> of type System.IdentityModel.Tokens::SecurityToken. |
| Name | Description | |
|---|---|---|
![]() ![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetCallbackChannel<T> | Gets a channel to the client instance that called the current operation. |
![]() ![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | SetTransactionComplete | Commits the currently executing transaction. |
![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
Use the OperationContext from within a service operation to access the current operation execution environment. In particular, the operation context is used to access callback channels in duplex services, to store extra state data across portions of the operations, and to access incoming message headers and properties as well as add outgoing message headers and properties.
For more information about using extensions to store state data, see Extensible Objects.
The OperationContext has the following properties and methods.
The Current property returns the OperationContext object representing the current execution context.
The ServiceSecurityContext property returns the security environment under which the method executes.
The EndpointDispatcher property gets the operation's System.ServiceModel.Dispatcher::EndpointDispatcher.
The Extensions property returns an extension collection for the current OperationContext.
The Host property returns the ServiceHostBase object that manages the service.
The HasSupportingTokens property returns a value that indicates whether the method has supporting tokens, if so, the SupportingTokens property gets them.
The IncomingMessageHeaders, IncomingMessageProperties, and IncomingMessageVersion properties get these items from the incoming message.
The OperationCompleted event is fired when the operation has completed.
The OutgoingMessageHeaders and OutgoingMessageProperties properties get these items for the outbound message.
The RequestContext property returns the RequestContext implementation for the method.
The InstanceContext property returns the InstanceContext associated with the operation.
The SessionId property returns the session identifier for the current channel and object.
The GetCallbackChannel<T> method returns a callback channel to the caller in the case of duplex communication.
The SetTransactionComplete method commits the current transaction.
The following code example uses the Current property and GetCallbackChannel<T> method to obtain the channel back to the caller from within a method. All methods in this example are one-way methods, enabling the service and the client to communicate in both directions independently. In this case, the example client application expects only one return call before it exits, but another client, for example a Windows Forms client, can receive any number of calls from the service.
The following client implements the SampleDuplexHelloCallback to receive the callback message. The imported callback contract is not the same name as the one in the service, due to the use of the Name property in the preceding example. Note that the client makes no assumptions about whether or when it might receive a callback; the server callback is entirely independent of the client's outbound call.
Note |
|---|
For an example that uses the OperationContext class in a client scenario, see OperationContextScope. |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

