MessageHeaders 類別

定義

表示訊息的訊息標頭集合。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)
繼承
MessageHeaders
實作

範例

下列程式碼範例示範使用通道處理站傳送訊息,並且從回覆讀取 Action 標頭的基本用戶端。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

備註

訊息標頭包含選擇性中繼資料,其中描述由 Message 類別所封裝的訊息。A message header contains optional metadata that describe a message encapsulated by the Message class.

Message 可以有零個或更多的標頭 (當做擴充機制使用),以便在應用程式特定的訊息中傳遞資訊。A Message can have zero or more headers that are used as an extension mechanism to pass information in messages that are application-specific. 您可以藉由呼叫 Headers 方法,使用 Add 將訊息標頭新增至訊息中。You can use Headers to add message headers to a message by calling the Add method.

Windows Communication Foundation (WCF)提供許多預先定義的訊息標頭: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.
FaultToFaultTo 包含錯誤應該傳送之目標節點的位址。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.
MessageIDMessageID 包含此訊息的唯一 ID。Contains the unique ID of the message.
RelatesToRelatesTo 包含與此訊息相關之訊息的 ID。Contains the IDs of messages that are related to this message.
ReplyToReplyTo 包含應該針對要求傳送回覆之目標節點的位址。Contains the address of the node to which a reply should be sent for a request.

建構函式

MessageHeaders(MessageHeaders)

使用指定的訊息標頭集合,初始化 MessageHeaders 類別的新執行個體。Initializes a new instance of the MessageHeaders class with the specified collection of message headers.

MessageHeaders(MessageVersion)

使用指定的訊息版本,初始化 MessageHeaders 類別的新執行個體。Initializes a new instance of the MessageHeaders class with the specified message version.

MessageHeaders(MessageVersion, Int32)

使用指定的訊息版本和大小,初始化 MessageHeaders 類別的新執行個體。Initializes a new instance of the MessageHeaders class with the specified message version and size.

屬性

Action

取得或設定應該如何處理訊息的描述。Gets or sets a description of how the message should be processed.

Count

取得這個集合中的訊息標頭數目。Gets the number of message headers in this collection.

FaultTo

取得或設定錯誤應該傳送之目標節點的位址。Gets or sets the address of the node to which faults should be sent.

From

取得或設定傳送訊息之節點的位址。Gets or sets the address of the node that sent the message.

Item[Int32]

擷取在指定索引處的標頭。Retrieves a header at the given index.

MessageId

取得或設定訊息的唯一 ID。Gets or sets the unique ID of the message.

MessageVersion

取得訊息的 SOAP 版本。Gets the SOAP version of the message.

RelatesTo

取得與此訊息相關之訊息的 ID。Gets the IDs of messages that are related to this message.

ReplyTo

取得或設定應該針對要求傳送回覆之目標節點的位址。Gets or sets the address of the node to which a reply should be sent for a request.

To

取得或設定訊息的目的端點。Gets or sets the destination endpoint of a message.

UnderstoodHeaders

根據 SOAP 1.1/1.2 規格取得必須解讀的所有訊息標頭。Gets all the message headers that must be understood, according to SOAP 1.1/1.2 specification.

方法

Add(MessageHeader)

將指定的訊息標頭加入至集合。Adds the specified message header to the collection.

Clear()

移除集合中的所有標頭。Removes all the headers from the collection.

CopyHeaderFrom(Message, Int32)

從指定的訊息將位於指定索引處的標頭內容複製到這個執行個體。Copies the header content located at the specified index from the specified message to this instance.

CopyHeaderFrom(MessageHeaders, Int32)

從指定的訊息標頭集合將位於指定索引處的標頭內容複製到這個執行個體。Copies the header content located at the specified index from the specified message header collection to this instance.

CopyHeadersFrom(Message)

從指定的訊息將所有標頭的內容複製到這個執行個體。Copies the content of all the headers from the specified message to this instance.

CopyHeadersFrom(MessageHeaders)

從指定的標頭集合將內容複製到這個執行個體。Copies the content from the specified header collection to this instance.

CopyTo(MessageHeaderInfo[], Int32)

從陣列的特定索引開始,將這個集合的標頭複製至陣列。Copies the headers from this collection to an array, starting at a particular index of the array.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
FindHeader(String, String)

藉由指定的 LocalName 和標頭項目之命名空間 URI,在這個集合中尋找訊息標頭。Finds a message header in this collection by the specified LocalName and namespace URI of the header element.

FindHeader(String, String, String[])

藉由指定的 LocalName、標頭項目之命名空間 URI 和 Actor,在這個集合中尋找訊息標頭。Finds a message header in this collection by the specified LocalName, namespace URI and actors of the header element.

GetEnumerator()

傳回可逐一查看集合的列舉值。Returns an enumerator for iterating through the collection. 這個方法無法被繼承。This method cannot be inherited.

GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetHeader<T>(Int32)

擷取這個集合中特定位置的訊息標頭。Retrieves a message header at a specific position in this collection.

GetHeader<T>(Int32, XmlObjectSerializer)

擷取這個集合中特定位置的訊息標頭。Retrieves a message header at a specific position in this collection.

GetHeader<T>(String, String)

藉由指定的 LocalName 和標頭項目之命名空間 URI,在這個集合中尋找訊息標頭。Finds a message header in this collection by the specified LocalName and namespace URI of the header element.

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

藉由指定的 LocalName、標頭項目之命名空間 URI 和 Actor,在這個集合中擷取訊息標頭。Retrieves a message header in this collection by the specified LocalName, namespace URI and actors of the header element.

GetHeader<T>(String, String, XmlObjectSerializer)

藉由指定的 LocalName、命名空間 URI 和序列化程式,在這個集合中擷取訊息標頭。Retrieves a message header in this collection by the specified LocalName, namespace URI and serializer.

GetReaderAtHeader(Int32)

取得會從集合中指定位置取用訊息標頭的 XML 字典讀取器。Gets a XML dictionary reader that consumes the message header at the specified location of the collection.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
HaveMandatoryHeadersBeenUnderstood()

驗證是否已正確解譯及處理以 MustUnderstand 標記的所有訊息標頭。Verifies whether all the message headers marked with MustUnderstand have been properly interpreted and processed.

HaveMandatoryHeadersBeenUnderstood(String[])

驗證指定的收件者是否已正確解譯及處理以 MustUnderstand 標記的所有訊息標頭。Verifies whether the specified recipients have properly interpreted and processed all the message headers marked with MustUnderstand.

Insert(Int32, MessageHeader)

將訊息標頭插入至集合中的指定索引處。Inserts a message header into the collection at the specified index.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
RemoveAll(String, String)

使用指定的名稱與命名空間從集合移除所有標頭。Removes all headers with the specified name and namespace from the collection.

RemoveAt(Int32)

從集合的指定索引處移除訊息標頭。Removes the message header at the specified index from the collection.

SetAction(XmlDictionaryString)

設定標頭的 Action 項目。Sets the action element of the header.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
WriteHeader(Int32, XmlDictionaryWriter)

使用指定的 XML 寫入器從指定的位置序列化標頭。Serializes the header from the specified location using the specified XML writer.

WriteHeader(Int32, XmlWriter)

使用指定的 XML 寫入器從指定的位置序列化標頭。Serializes the header from the specified location using the specified XML writer.

WriteHeaderContents(Int32, XmlDictionaryWriter)

使用指定的 XML 寫入器序列化指定的標頭內容。Serializes the specified header content using the specified XML writer.

WriteHeaderContents(Int32, XmlWriter)

使用指定的 XML 寫入器序列化指定的標頭內容。Serializes the specified header content using the specified XML writer.

WriteStartHeader(Int32, XmlDictionaryWriter)

使用指定的 XML 寫入器序列化開始標頭。Serializes the start header using the specified XML writer.

WriteStartHeader(Int32, XmlWriter)

使用指定的 XML 寫入器序列化開始標頭。Serializes the start header using the specified XML writer.

明確介面實作

IEnumerable.GetEnumerator()

傳回可逐一查看集合的列舉值。Returns an enumerator for iterating through the collection. 這個方法無法被繼承。This method cannot be inherited.

擴充方法

CopyToDataTable<T>(IEnumerable<T>)

根據輸入 DataTable 物件 (其中泛型參數 TDataRow) 傳回包含 IEnumerable<T> 物件複本的 DataRowReturns 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)

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 IEnumerable<T> 物件複製到指定的 DataRowCopies 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)

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 IEnumerable<T> 物件複製到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

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)

傳回包含來源集合中每個節點祖系的已篩選項目集合。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>)

傳回來源集合中每個文件和項目之子代節點的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

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)

傳回已篩選的項目集合,其中包含來源集合中每個項目和文件的子代項目。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

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)

傳回來源集合中每個項目和文件的已篩選子項目集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

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>)

傳回來源集合中每個文件和項目的子節點集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>)

在來源集合中,從每一個節點的父節點移除這些節點。Removes every node in the source collection from its parent node.

適用於