Message.Headers 속성

정의

파생 클래스에서 재정의되는 경우 메시지의 헤더를 가져옵니다.

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

속성 값

MessageHeaders

메시지의 헤더를 나타내는 MessageHeaders 개체입니다.

예외

메시지가 삭제된 경우

예제

다음 코드 예제에서는 채널 팩터리를 사용하여 메시지를 보내고 회신을 읽는 클라이언트를 보여 줍니다.

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Runtime.Serialization;

namespace ConsoleApplication1
{
    class client
    {

        static void RunClient()
        {
            //Step1: create a binding with just HTTP
            CustomBinding binding = new CustomBinding();
            binding.Elements.Add(new HttpTransportBindingElement());
            //Step2: use the binding to build the channel factory
            IChannelFactory<IRequestChannel> factory =
            binding.BuildChannelFactory<IRequestChannel>(
                             new BindingParameterCollection());
            //open the channel factory
            factory.Open();
            //Step3: use the channel factory to create a channel
            IRequestChannel channel = factory.CreateChannel(
               new EndpointAddress("http://localhost:8080/channelapp"));
            channel.Open();
            //Step4: create a message
            Message requestmessage = Message.CreateMessage(
                MessageVersion.Soap12WSAddressing10,
                "http://contoso.com/someaction",
                 "This is the body data");
            //send message
            Message replymessage = channel.Request(requestmessage);
            Console.WriteLine("Reply message received");
            Console.WriteLine("Reply action: {0}",
                                  replymessage.Headers.Action);
            string data = replymessage.GetBody<string>();
            Console.WriteLine("Reply content: {0}", data);
            //Step5: don't forget to close the message
            requestmessage.Close();
            replymessage.Close();
            //don't forget to close the channel
            channel.Close();
            //don't forget to close the factory
            factory.Close();
        }
        public static void Main()
        {
            Console.WriteLine("Press [ENTER] when service is ready");
            Console.ReadLine();
            RunClient();
            Console.WriteLine("Press [ENTER] to exit");
            Console.ReadLine();
        }
    }
}


Imports System.Collections.Generic
Imports System.Text
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Runtime.Serialization

Namespace ConsoleApplication1
    Friend Class client


        Private Shared Sub RunClient()
            'Step1: create a binding with just HTTP
            Dim binding As New CustomBinding()
            binding.Elements.Add(New HttpTransportBindingElement())
            'Step2: use the binding to build the channel factory
            Dim factory As IChannelFactory(Of IRequestChannel) = binding.BuildChannelFactory(Of IRequestChannel)(New BindingParameterCollection())
            'open the channel factory
            factory.Open()
            'Step3: use the channel factory to create a channel
            Dim channel As IRequestChannel = factory.CreateChannel(New EndpointAddress("http://localhost:8080/channelapp"))
            channel.Open()
            'Step4: create a message
            Dim requestmessage As Message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "http://contoso.com/someaction", "This is the body data")
            'send message
            Dim replymessage As Message = channel.Request(requestmessage)
            Console.WriteLine("Reply message received")
            Console.WriteLine("Reply action: {0}", replymessage.Headers.Action)
            Dim data = replymessage.GetBody(Of String)()
            Console.WriteLine("Reply content: {0}", data)
            'Step5: don't forget to close the message
            requestmessage.Close()
            replymessage.Close()
            'don't forget to close the channel
            channel.Close()
            'don't forget to close the factory
            factory.Close()
        End Sub
        Public Shared Sub Main()
            Console.WriteLine("Press [ENTER] when service is ready")
            Console.ReadLine()
            RunClient()
            Console.WriteLine("Press [ENTER] to exit")
            Console.ReadLine()
        End Sub
    End Class
End Namespace

설명

Message에는 애플리케이션 고유의 정보를 메시지로 전달하기 위한 확장명 메커니즘으로 사용되는 헤더가 하나 이상 있거나 없을 수 있습니다. 메서드를 호출 Add 하여 메시지에 메시지 헤더를 추가하는 데 사용할 Headers 수 있습니다.

Windows Communication Foundation(WCF)은 다음 표와 같이 미리 정의된 여러 메시지 헤더를 제공합니다.

헤더 이름 헤더 이름을 포함합니다.
대상 메시지가 대상으로 하는 역할을 포함합니다.
작업 메시지를 처리하는 방법에 대한 설명을 제공합니다.
FaultTo 오류를 보내야 하는 노드의 주소를 포함합니다.
시작 메시지를 보낸 노드의 주소를 포함합니다.
요청 메시지가 요청인지 여부를 나타냅니다.
MessageID 메시지의 고유 ID를 포함합니다.
RelatesTo 이 메시지와 관련된 메시지의 ID를 포함합니다.
ReplyTo 요청에 대한 회신을 보내야 하는 노드의 주소를 포함합니다.

구현자 참고

파생 클래스에서 재정의되는 경우 이 메서드는 메시지의 헤더에 대한 개체를 반환 MessageHeaders 합니다.

적용 대상