Message.Headers Właściwość

Definicja

Po przesłonięciu w klasie pochodnej pobiera nagłówki komunikatu.

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

Wartość właściwości

MessageHeaders

MessageHeaders Obiekt reprezentujący nagłówki wiadomości.

Wyjątki

Wiadomość została usunięta.

Przykłady

Poniższy przykład kodu przedstawia klienta, który używa fabryki kanałów do wysyłania wiadomości i odczytywania odpowiedzi.

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

Uwagi

Element Message może mieć zero lub więcej nagłówków, które są używane jako mechanizm rozszerzenia do przekazywania informacji w komunikatach specyficznych dla aplikacji. Możesz użyć Headers polecenia , aby dodać nagłówki komunikatów do wiadomości, wywołując metodę Add .

Windows Communication Foundation (WCF) udostępnia szereg wstępnie zdefiniowanych nagłówków komunikatów, jak pokazano w poniższej tabeli.

Nazwa nagłówka Zawiera nazwę nagłówka.
Działanie Zawiera rolę docelową komunikatu.
Akcja Zawiera opis sposobu przetwarzania komunikatu.
FaultTo Zawiera adres węzła, do którego powinny zostać wysłane błędy.
Źródło Zawiera adres węzła, który wysłał wiadomość.
Żądanie Wskazuje, czy komunikat jest żądaniem.
Messageid Zawiera unikatowy identyfikator komunikatu.
RelatesTo Zawiera identyfikatory komunikatów powiązanych z tym komunikatem.
Replyto Zawiera adres węzła, do którego powinna zostać wysłana odpowiedź na żądanie.

Uwagi dotyczące implementowania

Po przesłonięciu w klasie pochodnej ta metoda zwraca MessageHeaders obiekt nagłówków komunikatu.

Dotyczy