Freigeben über


OperationContextScope Konstruktoren

Definition

Initialisiert eine neue Instanz der OperationContextScope-Klasse.

Überlädt

Name Beschreibung
OperationContextScope(IContextChannel)

Initialisiert eine neue Instanz der Klasse, die OperationContextScope den angegebenen zum Erstellen eines neuen OperationContext Bereichs verwendetIContextChannel.

OperationContextScope(OperationContext)

Initialisiert eine neue Instanz der OperationContextScope Klasse, um einen Bereich für das angegebene OperationContext Objekt zu erstellen.

OperationContextScope(IContextChannel)

Quelle:
OperationContextScope.cs
Quelle:
OperationContextScope.cs
Quelle:
OperationContextScope.cs

Initialisiert eine neue Instanz der Klasse, die OperationContextScope den angegebenen zum Erstellen eines neuen OperationContext Bereichs verwendetIContextChannel.

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)

Parameter

channel
IContextChannel

Der Kanal, der beim Erstellen des Bereichs für ein neues OperationContextverwendet werden soll.

Beispiele

Das folgende Beispiel zeigt, wie Sie mit dem OperationContextScope Neuen Kontext in einer Clientanwendung einen neuen Kontext erstellen, um der ausgehenden Nachricht einen benutzerdefinierten Header hinzuzufügen.

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

Hinweise

Verwenden Sie den OperationContextScope Konstruktor, um einen neuen OperationContext Für einen Clientkanal zu erstellen, der verwendet werden kann, um ausgehende Nachrichtenkopfzeilen hinzuzufügen oder zu ändern, eingehende Nachrichtenkopfzeilen zu lesen oder auf andere Laufzeiteigenschaften der .OperationContext

Die Kopfzeilen, die der OperationContext.IncomingMessageHeaders Eigenschaft der neu erstellten Erstellung OperationContext hinzugefügt wurden, gelten nur für den Kanal, der an den OperationContextScope Konstruktor übergeben wurde. Wenn der Benutzer einen neuen Kanal innerhalb seines Bereichs erstellt, werden die Kopfzeilen nicht auf Nachrichten angewendet, die auf dem neuen Kanal gesendet werden.

Gilt für:

OperationContextScope(OperationContext)

Quelle:
OperationContextScope.cs
Quelle:
OperationContextScope.cs
Quelle:
OperationContextScope.cs

Initialisiert eine neue Instanz der OperationContextScope Klasse, um einen Bereich für das angegebene OperationContext Objekt zu erstellen.

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)

Parameter

context
OperationContext

Das Aktive OperationContext im erstellten Bereich.

Hinweise

Verwenden Sie den OperationContextScope Konstruktor, um einen Codeblock zu erstellen, in dem das angegebene OperationContextScope Objekt der aktuelle Bereich ist.

Gilt für: