다음을 통해 공유


OperationContext.IncomingMessageHeaders 속성

정의

OperationContext의 들어오는 메시지 헤더를 가져옵니다.

public:
 property System::ServiceModel::Channels::MessageHeaders ^ IncomingMessageHeaders { System::ServiceModel::Channels::MessageHeaders ^ get(); };
public System.ServiceModel.Channels.MessageHeaders IncomingMessageHeaders { get; }
member this.IncomingMessageHeaders : System.ServiceModel.Channels.MessageHeaders
Public ReadOnly Property IncomingMessageHeaders As MessageHeaders

속성 값

MessageHeaders

들어오는 메시지 헤더가 포함된 MessageHeaders 개체입니다.

예제

다음 코드 예제에서는 서비스 작업에서 들어오는 메시지 헤더를 읽는 방법을 보여 줍니다.

class SampleService : ISampleService
{
#region ISampleService Members

  public void Push(string msg)
  {
      Console.WriteLine("Proxy: " + msg);
    this.WriteHeaders(OperationContext.Current.IncomingMessageHeaders);
    MessageHeader outBoundHeader
      = MessageHeader.CreateHeader(
        "Client-Bound-One-Way-Header",
        "http://Microsoft.WCF.Documentation",
        "Custom Outbound Header"
      );
    OperationContext.Current.OutgoingMessageHeaders.Add(outBoundHeader);
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("OutgoingHeader:");
    Console.Write("\t");
    Console.ForegroundColor = ConsoleColor.Blue;
    Console.WriteLine(outBoundHeader.ToString());
    Console.ResetColor();
    OperationContext.Current.GetCallbackChannel<IClientCallbackContract>().PushBack("Here's something to examine in response.");
  }

  void WriteHeaders(MessageHeaders headers)
  {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("IncomingHeader:");
    Console.ForegroundColor = ConsoleColor.Blue;
    foreach (MessageHeaderInfo h in headers)
    {
      if (!h.Actor.Equals(String.Empty))
        Console.WriteLine("\t" + h.Actor);
      Console.ForegroundColor = ConsoleColor.White;
      Console.WriteLine("\t" + h.Name);
      Console.ForegroundColor = ConsoleColor.Blue;
      Console.WriteLine("\t" + h.Namespace);
      Console.WriteLine("\t" + h.Relay);
      if (h.IsReferenceParameter == true)
      {
          Console.WriteLine("IsReferenceParameter header detected: " + h.ToString());
      }
    }
    Console.ResetColor();
  }
Friend Class SampleService
    Implements ISampleService
#Region "ISampleService Members"

  Public Sub Push(ByVal msg As String) Implements ISampleService.Push
       Console.WriteLine("Proxy: " & msg)
    Me.WriteHeaders(OperationContext.Current.IncomingMessageHeaders)
    Dim outBoundHeader As MessageHeader = MessageHeader.CreateHeader("Client-Bound-One-Way-Header", "http://Microsoft.WCF.Documentation", "Custom Outbound Header")
    OperationContext.Current.OutgoingMessageHeaders.Add(outBoundHeader)
    Console.ForegroundColor = ConsoleColor.Red
    Console.WriteLine("OutgoingHeader:")
    Console.Write(vbTab)
    Console.ForegroundColor = ConsoleColor.Blue
    Console.WriteLine(outBoundHeader.ToString())
    Console.ResetColor()
    OperationContext.Current.GetCallbackChannel(Of IClientCallbackContract)().PushBack("Here's something to examine in response.")
  End Sub

  Private Sub WriteHeaders(ByVal headers As MessageHeaders)
    Console.ForegroundColor = ConsoleColor.Red
    Console.WriteLine("IncomingHeader:")
    Console.ForegroundColor = ConsoleColor.Blue
          For Each h In headers
              If Not h.Actor.Equals(String.Empty) Then
                  Console.WriteLine(vbTab & h.Actor)
              End If
              Console.ForegroundColor = ConsoleColor.White
              Console.WriteLine(vbTab & h.Name)
              Console.ForegroundColor = ConsoleColor.Blue
              Console.WriteLine(vbTab & h.Namespace)
              Console.WriteLine(vbTab & h.Relay)
              If h.IsReferenceParameter = True Then
                  Console.WriteLine("IsReferenceParameter header detected: " & h.ToString())
              End If
          Next h
    Console.ResetColor()
  End Sub

설명

서비스 작업에 도착하는 요청 헤더나 클라이언트 프록시에 도착하는 회신 헤더를 검사하거나 수정하려면 이 속성을 사용합니다.

적용 대상