Dil

OperationContext.Current Özellik

Tanım

Geçerli iş parçacığı için yürütme bağlamını alır veya ayarlar.

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; }
static member Current : System.ServiceModel.OperationContext with get, set
Public Shared Property Current As OperationContext

Özellik Değeri

OperationContext Geçerli yöntemin mesajlaşma ve yürütme bağlamını temsil eden.

Örnekler

Aşağıdaki kod örneği, bir yöntemin Current içinden çağırana bir kanal oluşturmak için özelliğini ve GetCallbackChannel yöntemini kullanır. Bu örnekteki tüm yöntemler tek yönlü yöntemlerdir ve hizmetin ve istemcinin her iki yönde de bağımsız olarak iletişim kurmasını sağlar. Bu durumda, örnek istemci uygulaması çıkmadan önce yalnızca bir dönüş çağrısı bekler, ancak başka bir istemci, örneğin bir Windows Forms istemcisi hizmetten herhangi bir sayıda çağrı alabilir.

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);
    }
  }
}

Açıklamalar

Geçerli yöntemin Current yürütme ve ileti bağlamını almak için özelliğini kullanın.

Şunlara uygulanır