OperationContextScope 생성자

정의

OperationContextScope 클래스의 새 인스턴스를 초기화합니다.

오버로드

OperationContextScope(IContextChannel)

지정된 OperationContextScope을 사용하여 범위에 대해 새 IContextChannel를 만드는 OperationContext 클래스의 새 인스턴스를 초기화합니다.

OperationContextScope(OperationContext)

지정된 OperationContextScope 개체의 범위를 만들기 위해 OperationContext 클래스의 새 인스턴스를 초기화합니다.

OperationContextScope(IContextChannel)

지정된 OperationContextScope을 사용하여 범위에 대해 새 IContextChannel를 만드는 OperationContext 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

channel
IContextChannel

OperationContext의 범위를 만들 때 사용할 채널입니다.

예제

다음 예제에서는 보내는 메시지에 사용자 지정 헤더를 추가하기 위해 OperationContextScope를 사용하여 클라이언트 애플리케이션에서 새 컨텍스트를 만드는 방법을 보여 줍니다.

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

설명

OperationContextScope 생성자를 사용하여 아웃바운드 메시지 헤더를 추가 또는 수정하거나, 들어오는 메시지 헤더를 읽거나, 클라이언트 채널의 OperationContext다른 런타임 속성에 액세스하는 데 사용할 수 있는 새 클라이언트 채널을 만듭니 OperationContext 다.

새로 만든 OperationContext 속성에 OperationContext.IncomingMessageHeaders 추가된 헤더는 생성자에 전달된 채널에 OperationContextScope 만 적용됩니다. 사용자가 범위 내에 새 채널을 만드는 경우 헤더는 새 채널에서 보낸 메시지에 적용되지 않습니다.

적용 대상

OperationContextScope(OperationContext)

지정된 OperationContextScope 개체의 범위를 만들기 위해 OperationContext 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

context
OperationContext

만들어진 범위의 활성 OperationContext입니다.

설명

OperationContextScope 생성자를 사용하여 지정된 OperationContextScope 개체가 현재 범위인 코드 블록을 만듭니다.

적용 대상