Provides access to the execution context of a service method.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
Thetype exposes the following members.
|Channel||Gets the channel associated with the current 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 .|
|IncomingMessageProperties||Gets the message properties for the incoming message in the .|
|IncomingMessageVersion||Gets the incoming SOAP message version for the .|
|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 .|
|OutgoingMessageProperties||Gets the message properties for the outbound message in the active .|
|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(Of T) of type System.IdentityModel.Tokens.SecurityToken.|
|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(Of 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 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 has the following properties and methods.
The Current property returns the object representing the current execution context.
The ServiceSecurityContext property returns the security environment under which the method executes.
The Extensions property returns an extension collection for the current .
The OperationCompleted event is fired when the operation has completed.
The SessionId property returns the session identifier for the current channel and object.
The GetCallbackChannel(Of 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(Of 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.
Imports System Imports System.Collections.Generic Imports System.ServiceModel Imports System.Threading Namespace Microsoft.WCF.Documentation <ServiceContract(Name:="SampleDuplexHello", Namespace:="http://microsoft.wcf.documentation", _ CallbackContract:=GetType(IHelloCallbackContract), SessionMode:=SessionMode.Required)> _ Public Interface IDuplexHello <OperationContract(IsOneWay:=True)> _ Sub Hello(ByVal greeting As String) End Interface Public Interface IHelloCallbackContract <OperationContract(IsOneWay := True)> _ Sub Reply(ByVal responseToGreeting As String) End Interface Public Class DuplexHello Implements IDuplexHello Public Sub New() Console.WriteLine("Service object created: " & Me.GetHashCode().ToString()) End Sub Protected Overrides Sub Finalize() Console.WriteLine("Service object destroyed: " & Me.GetHashCode().ToString()) End Sub Public Sub Hello(ByVal greeting As String) Implements IDuplexHello.Hello Console.WriteLine("Caller sent: " & greeting) Console.WriteLine("Session ID: " & OperationContext.Current.SessionId) Console.WriteLine("Waiting two seconds before returning call.") ' Put a slight delay to demonstrate asynchronous behavior on client. Thread.Sleep(2000) Dim callerProxy = OperationContext.Current.GetCallbackChannel(Of IHelloCallbackContract)() Dim response = "Service object " & Me.GetHashCode().ToString() & " received: " & greeting Console.WriteLine("Sending back: " & response) callerProxy.Reply(response) End Sub End Class End Namespace
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.
For an example that uses the 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.