MessageHeaders MessageHeaders MessageHeaders MessageHeaders Class

Definition

Represents a collection of message headers for a message. This class cannot be inherited.

public ref class MessageHeaders sealed : System::Collections::Generic::IEnumerable<System::ServiceModel::Channels::MessageHeaderInfo ^>
public sealed class MessageHeaders : System.Collections.Generic.IEnumerable<System.ServiceModel.Channels.MessageHeaderInfo>
type MessageHeaders = class
    interface seq<MessageHeaderInfo>
    interface IEnumerable
Public NotInheritable Class MessageHeaders
Implements IEnumerable(Of MessageHeaderInfo)
Inheritance
MessageHeadersMessageHeadersMessageHeadersMessageHeaders
Implements

Examples

The following code example demonstrates a basic client using the channel factory to send a message and read the action header from the reply.

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

Remarks

A message header contains optional metadata that describe a message encapsulated by the Message class.

A Message can have zero or more headers that are used as an extension mechanism to pass information in messages that are application-specific. You can use Headers to add message headers to a message by calling the Add method.

Windows Communication Foundation (WCF) provides a number of predefined message headers:

Header Name Description
To Contains the role that the message is targeting.
Action Provides a description of how the message should be processed.
FaultTo Contains the address of the node to which faults should be sent.
From Contains the address of the node that sent the message.
Request Indicates whether the message is a request.
MessageID Contains the unique ID of the message.
RelatesTo Contains the IDs of messages that are related to this message.
ReplyTo Contains the address of the node to which a reply should be sent for a request.

Constructors

MessageHeaders(MessageHeaders) MessageHeaders(MessageHeaders) MessageHeaders(MessageHeaders) MessageHeaders(MessageHeaders)

Initializes a new instance of the MessageHeaders class with the specified collection of message headers.

MessageHeaders(MessageVersion) MessageHeaders(MessageVersion) MessageHeaders(MessageVersion) MessageHeaders(MessageVersion)

Initializes a new instance of the MessageHeaders class with the specified message version.

MessageHeaders(MessageVersion, Int32) MessageHeaders(MessageVersion, Int32) MessageHeaders(MessageVersion, Int32) MessageHeaders(MessageVersion, Int32)

Initializes a new instance of the MessageHeaders class with the specified message version and size.

Properties

Action Action Action Action

Gets or sets a description of how the message should be processed.

Count Count Count Count

Gets the number of message headers in this collection.

FaultTo FaultTo FaultTo FaultTo

Gets or sets the address of the node to which faults should be sent.

From From From From

Gets or sets the address of the node that sent the message.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Retrieves a header at the given index.

MessageId MessageId MessageId MessageId

Gets or sets the unique ID of the message.

MessageVersion MessageVersion MessageVersion MessageVersion

Gets the SOAP version of the message.

RelatesTo RelatesTo RelatesTo RelatesTo

Gets the IDs of messages that are related to this message.

ReplyTo ReplyTo ReplyTo ReplyTo

Gets or sets the address of the node to which a reply should be sent for a request.

To To To To

Gets or sets the destination endpoint of a message.

UnderstoodHeaders UnderstoodHeaders UnderstoodHeaders UnderstoodHeaders

Gets all the message headers that must be understood, according to SOAP 1.1/1.2 specification.

Methods

Add(MessageHeader) Add(MessageHeader) Add(MessageHeader) Add(MessageHeader)

Adds the specified message header to the collection.

Clear() Clear() Clear() Clear()

Removes all the headers from the collection.

CopyHeaderFrom(Message, Int32) CopyHeaderFrom(Message, Int32) CopyHeaderFrom(Message, Int32) CopyHeaderFrom(Message, Int32)

Copies the header content located at the specified index from the specified message to this instance.

CopyHeaderFrom(MessageHeaders, Int32) CopyHeaderFrom(MessageHeaders, Int32) CopyHeaderFrom(MessageHeaders, Int32) CopyHeaderFrom(MessageHeaders, Int32)

Copies the header content located at the specified index from the specified message header collection to this instance.

CopyHeadersFrom(Message) CopyHeadersFrom(Message) CopyHeadersFrom(Message) CopyHeadersFrom(Message)

Copies the content of all the headers from the specified message to this instance.

CopyHeadersFrom(MessageHeaders) CopyHeadersFrom(MessageHeaders) CopyHeadersFrom(MessageHeaders) CopyHeadersFrom(MessageHeaders)

Copies the content from the specified header collection to this instance.

CopyTo(MessageHeaderInfo[], Int32) CopyTo(MessageHeaderInfo[], Int32) CopyTo(MessageHeaderInfo[], Int32) CopyTo(MessageHeaderInfo[], Int32)

Copies the headers from this collection to an array, starting at a particular index of the array.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
FindHeader(String, String) FindHeader(String, String) FindHeader(String, String) FindHeader(String, String)

Finds a message header in this collection by the specified LocalName and namespace URI of the header element.

FindHeader(String, String, String[]) FindHeader(String, String, String[]) FindHeader(String, String, String[]) FindHeader(String, String, String[])

Finds a message header in this collection by the specified LocalName, namespace URI and actors of the header element.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Returns an enumerator for iterating through the collection. This method cannot be inherited.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetHeader<T>(Int32) GetHeader<T>(Int32) GetHeader<T>(Int32) GetHeader<T>(Int32)

Retrieves a message header at a specific position in this collection.

GetHeader<T>(Int32, XmlObjectSerializer) GetHeader<T>(Int32, XmlObjectSerializer) GetHeader<T>(Int32, XmlObjectSerializer) GetHeader<T>(Int32, XmlObjectSerializer)

Retrieves a message header at a specific position in this collection.

GetHeader<T>(String, String) GetHeader<T>(String, String) GetHeader<T>(String, String) GetHeader<T>(String, String)

Finds a message header in this collection by the specified LocalName and namespace URI of the header element.

GetHeader<T>(String, String, String[]) GetHeader<T>(String, String, String[]) GetHeader<T>(String, String, String[]) GetHeader<T>(String, String, String[])

Retrieves a message header in this collection by the specified LocalName, namespace URI and actors of the header element.

GetHeader<T>(String, String, XmlObjectSerializer) GetHeader<T>(String, String, XmlObjectSerializer) GetHeader<T>(String, String, XmlObjectSerializer) GetHeader<T>(String, String, XmlObjectSerializer)

Retrieves a message header in this collection by the specified LocalName, namespace URI and serializer.

GetReaderAtHeader(Int32) GetReaderAtHeader(Int32) GetReaderAtHeader(Int32) GetReaderAtHeader(Int32)

Gets a XML dictionary reader that consumes the message header at the specified location of the collection.

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
HaveMandatoryHeadersBeenUnderstood() HaveMandatoryHeadersBeenUnderstood() HaveMandatoryHeadersBeenUnderstood() HaveMandatoryHeadersBeenUnderstood()

Verifies whether all the message headers marked with MustUnderstand have been properly interpreted and processed.

HaveMandatoryHeadersBeenUnderstood(String[]) HaveMandatoryHeadersBeenUnderstood(String[]) HaveMandatoryHeadersBeenUnderstood(String[]) HaveMandatoryHeadersBeenUnderstood(String[])

Verifies whether the specified recipients have properly interpreted and processed all the message headers marked with MustUnderstand.

Insert(Int32, MessageHeader) Insert(Int32, MessageHeader) Insert(Int32, MessageHeader) Insert(Int32, MessageHeader)

Inserts a message header into the collection at the specified index.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
RemoveAll(String, String) RemoveAll(String, String) RemoveAll(String, String) RemoveAll(String, String)

Removes all headers with the specified name and namespace from the collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Removes the message header at the specified index from the collection.

SetAction(XmlDictionaryString) SetAction(XmlDictionaryString) SetAction(XmlDictionaryString) SetAction(XmlDictionaryString)

Sets the action element of the header.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)
WriteHeader(Int32, XmlDictionaryWriter) WriteHeader(Int32, XmlDictionaryWriter) WriteHeader(Int32, XmlDictionaryWriter) WriteHeader(Int32, XmlDictionaryWriter)

Serializes the header from the specified location using the specified XML writer.

WriteHeader(Int32, XmlWriter) WriteHeader(Int32, XmlWriter) WriteHeader(Int32, XmlWriter) WriteHeader(Int32, XmlWriter)

Serializes the header from the specified location using the specified XML writer.

WriteHeaderContents(Int32, XmlDictionaryWriter) WriteHeaderContents(Int32, XmlDictionaryWriter) WriteHeaderContents(Int32, XmlDictionaryWriter) WriteHeaderContents(Int32, XmlDictionaryWriter)

Serializes the specified header content using the specified XML writer.

WriteHeaderContents(Int32, XmlWriter) WriteHeaderContents(Int32, XmlWriter) WriteHeaderContents(Int32, XmlWriter) WriteHeaderContents(Int32, XmlWriter)

Serializes the specified header content using the specified XML writer.

WriteStartHeader(Int32, XmlDictionaryWriter) WriteStartHeader(Int32, XmlDictionaryWriter) WriteStartHeader(Int32, XmlDictionaryWriter) WriteStartHeader(Int32, XmlDictionaryWriter)

Serializes the start header using the specified XML writer.

WriteStartHeader(Int32, XmlWriter) WriteStartHeader(Int32, XmlWriter) WriteStartHeader(Int32, XmlWriter) WriteStartHeader(Int32, XmlWriter)

Serializes the start header using the specified XML writer.

Explicit Interface Implementations

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

Returns an enumerator for iterating through the collection. This method cannot be inherited.

Extension Methods

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the ancestors of every node in the source collection. Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

Returns a filtered collection of the child elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

Removes every node in the source collection from its parent node.

Applies to