OperationContext.Current OperationContext.Current OperationContext.Current OperationContext.Current Property

Definition

Ruft den Ausführungskontext für den aktuellen Thread ab oder legt ihn fest.Gets or sets the execution context for the current thread.

public:
 static property System::ServiceModel::OperationContext ^ Current { System::ServiceModel::OperationContext ^ get(); void set(System::ServiceModel::OperationContext ^ value); };
public static System.ServiceModel.OperationContext Current { get; set; }
member this.Current : System.ServiceModel.OperationContext with get, set
Public Shared Property Current As OperationContext

Eigenschaftswert

Der OperationContext, der den Nachrichten- und Ausführungskontext der aktuellen Methode angibt.The OperationContext that represents the messaging and execution context of the current method.

Beispiele

Im nachstehenden Codebeispiel wird mit der Current-Eigenschaft und der GetCallbackChannel-Methode ein Kanal zurück zum Aufrufer aus einer Methode erstellt.The following code example uses the Current property and GetCallbackChannel method to create a channel back to the caller from within a method. Alle in diesem Beispiel verwendeten Methoden sind unidirektionale Methoden, die für den Dienst und den Client eine unabhängige Kommunikation in beide Richtungen ermöglichen.All methods in this example are one-way methods, enabling the service and the client to communicate in both directions independently. In diesem Fall erwartet die Beispielclientanwendung nur einen Rückgabeaufruf, bevor er beendet wird. Ein anderer Client, wie zum Beispiel ein Windows Forms-Client kann jedoch eine beliebige Anzahl Aufrufe von dem Dienst erhalten.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.

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Threading;

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(
    Name = "SampleDuplexHello",
    Namespace = "http://microsoft.wcf.documentation",
    CallbackContract = typeof(IHelloCallbackContract),
    SessionMode = SessionMode.Required
  )]
  public interface IDuplexHello
  {
    [OperationContract(IsOneWay = true)]
    void Hello(string greeting);
  }

  public interface IHelloCallbackContract
  {
    [OperationContract(IsOneWay = true)]
    void Reply(string responseToGreeting);
  }

  public class DuplexHello : IDuplexHello
  {
    public DuplexHello()
    {
      Console.WriteLine("Service object created: " + this.GetHashCode().ToString());
    }

    ~DuplexHello()
    {
      Console.WriteLine("Service object destroyed: " + this.GetHashCode().ToString());
    }

    public void Hello(string greeting)
    {
      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);
      IHelloCallbackContract callerProxy
        = OperationContext.Current.GetCallbackChannel<IHelloCallbackContract>();
      string response = "Service object " + this.GetHashCode().ToString() + " received: " + greeting;
      Console.WriteLine("Sending back: " + response);
      callerProxy.Reply(response);
    }
  }
}


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

Hinweise

Verwenden Sie die Current-Eigenschaft, um den Ausführungs- und Nachrichtenkontext für die aktuelle Methode zu erhalten.Use the Current property to obtain the execution and message context for the current method.

Gilt für: