Message.Headers プロパティ
定義
派生クラスでオーバーライドされた場合、メッセージのヘッダーを取得します。When overridden in a derived class, gets the headers of the message.
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 オブジェクト。A MessageHeaders object that represents the headers of the message.
例外
メッセージが破棄されました。The message has been disposed of.
例
次のコード例は、メッセージを送信して応答を読み取るためにチャネル ファクトリを使用する基本的なクライアントを示しています。The following code example shows a client that uses the channel factory to send a message and read 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 は、メッセージ内のアプリケーション固有の情報を渡すための拡張機構として使用される 0 個以上のヘッダーを持つことができます。A Message can have zero or more headers that are used as an extension mechanism to pass information in messages that is 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, as shown in the following table.
ヘッダー名Header Name | ヘッダー名を格納します。Contains the header name. |
---|---|
終了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. |
RequestRequest | メッセージが要求かどうかを示します。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 オブジェクトを返します。When overridden in a derived class, this method returns a MessageHeaders object for the headers of the message.