Lenguaje

OperationContext.Current Propiedad

Definición

Obtiene o establece el contexto de ejecución del subproceso actual.

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

Valor de propiedad

OperationContext que representa el contexto de mensajería y ejecución del método actual.

Ejemplos

En el ejemplo de código siguiente se usa la propiedad y Current el GetCallbackChannel método para crear un canal de vuelta al autor de la llamada desde dentro de un método . Todos los métodos de este ejemplo son métodos unidireccionales, lo que permite que el servicio y el cliente se comuniquen en ambas direcciones de forma independiente. En este caso, la aplicación cliente de ejemplo espera solo una llamada de devolución antes de que salga, pero otro cliente, por ejemplo, un cliente de Windows Forms, puede recibir cualquier número de llamadas del servicio.

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

Comentarios

Utilice la Current propiedad para obtener el contexto de ejecución y mensaje del método actual.

Se aplica a