OperationContextScope Oluşturucular

Tanım

OperationContextScope sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

OperationContextScope(IContextChannel)

Kapsam için yeni bir oluşturmak üzere belirtilen IContextChannel öğesini kullanan sınıfının yeni OperationContext bir örneğini OperationContextScope başlatır.

OperationContextScope(OperationContext)

Belirtilen OperationContext nesne için kapsam oluşturmak üzere sınıfının yeni bir örneğini OperationContextScope başlatır.

OperationContextScope(IContextChannel)

Kapsam için yeni bir oluşturmak üzere belirtilen IContextChannel öğesini kullanan sınıfının yeni OperationContext bir örneğini OperationContextScope başlatır.

public:
 OperationContextScope(System::ServiceModel::IContextChannel ^ channel);
public OperationContextScope (System.ServiceModel.IContextChannel channel);
new System.ServiceModel.OperationContextScope : System.ServiceModel.IContextChannel -> System.ServiceModel.OperationContextScope
Public Sub New (channel As IContextChannel)

Parametreler

channel
IContextChannel

Yeni OperationContextbir için kapsam oluştururken kullanılacak kanal.

Örnekler

Aşağıdaki örnekte, giden iletiye özel üst bilgi eklemek amacıyla istemci uygulamasında yeni bağlam oluşturmak için öğesinin nasıl kullanılacağı OperationContextScope gösterilmektedir.

SampleServiceClient wcfClient = new SampleServiceClient(new InstanceContext(this));
try
{
  using (OperationContextScope scope = new OperationContextScope(wcfClient.InnerChannel))
  {
    MessageHeader header
      = MessageHeader.CreateHeader(
      "Service-Bound-CustomHeader",
      "http://Microsoft.WCF.Documentation",
      "Custom Happy Value."
      );
    OperationContext.Current.OutgoingMessageHeaders.Add(header);

    // Making calls.
    Console.WriteLine("Enter the greeting to send: ");
    string greeting = Console.ReadLine();

    //Console.ReadLine();
    header = MessageHeader.CreateHeader(
        "Service-Bound-OneWayHeader",
        "http://Microsoft.WCF.Documentation",
        "Different Happy Value."
      );
    OperationContext.Current.OutgoingMessageHeaders.Add(header);

    // One-way
    wcfClient.Push(greeting);
    this.wait.WaitOne();

    // Done with service.
    wcfClient.Close();
    Console.WriteLine("Done!");
    Console.ReadLine();
  }
}
catch (TimeoutException timeProblem)
{
  Console.WriteLine("The service operation timed out. " + timeProblem.Message);
  Console.ReadLine();
  wcfClient.Abort();
}
catch (CommunicationException commProblem)
{
  Console.WriteLine("There was a communication problem. " + commProblem.Message);
  Console.ReadLine();
  wcfClient.Abort();
}
Dim wcfClient As New SampleServiceClient(New InstanceContext(Me))
Try
  Using scope As New OperationContextScope(wcfClient.InnerChannel)
            Dim header As MessageHeader = MessageHeader.CreateHeader("Service-Bound-CustomHeader", _
                                "http://Microsoft.WCF.Documentation", "Custom Happy Value.")
    OperationContext.Current.OutgoingMessageHeaders.Add(header)

    ' Making calls.
    Console.WriteLine("Enter the greeting to send: ")
    Dim greeting As String = Console.ReadLine()

    'Console.ReadLine();
            header = MessageHeader.CreateHeader("Service-Bound-OneWayHeader", _
                                                "http://Microsoft.WCF.Documentation", "Different Happy Value.")
    OperationContext.Current.OutgoingMessageHeaders.Add(header)

    ' One-way
    wcfClient.Push(greeting)
    Me.wait.WaitOne()

    ' Done with service. 
    wcfClient.Close()
    Console.WriteLine("Done!")
    Console.ReadLine()
  End Using
Catch timeProblem As TimeoutException
  Console.WriteLine("The service operation timed out. " & timeProblem.Message)
  Console.ReadLine()
  wcfClient.Abort()
Catch commProblem As CommunicationException
  Console.WriteLine("There was a communication problem. " & commProblem.Message)
  Console.ReadLine()
  wcfClient.Abort()
End Try

Açıklamalar

OperationContextScope Giden ileti üst bilgilerini eklemek veya değiştirmek, gelen ileti üst bilgilerini okumak veya diğer çalışma zamanı özelliklerine erişmek için kullanılabilecek bir istemci kanalı için yeni OperationContext bir oluşturmak üzere oluşturucuyu OperationContextkullanın.

Yeni oluşturulan OperationContext özelliğine OperationContext.IncomingMessageHeaders eklenen üst bilgiler yalnızca oluşturucuya geçirilen kanal için OperationContextScope geçerlidir. Kullanıcı kendi kapsamında yeni bir kanal oluşturursa, üst bilgiler yeni kanalda gönderilen iletilere uygulanmaz.

Şunlara uygulanır

OperationContextScope(OperationContext)

Belirtilen OperationContext nesne için kapsam oluşturmak üzere sınıfının yeni bir örneğini OperationContextScope başlatır.

public:
 OperationContextScope(System::ServiceModel::OperationContext ^ context);
public OperationContextScope (System.ServiceModel.OperationContext context);
new System.ServiceModel.OperationContextScope : System.ServiceModel.OperationContext -> System.ServiceModel.OperationContextScope
Public Sub New (context As OperationContext)

Parametreler

context
OperationContext

Oluşturulan kapsamdaki etkin OperationContext .

Açıklamalar

Belirtilen OperationContextScope nesnenin OperationContextScope geçerli kapsam olduğu bir kod bloğu oluşturmak için oluşturucuyu kullanın.

Şunlara uygulanır