HttpRequestMessageProperty 類別

定義

提供對 HTTP 要求的存取,以存取及回應透過 HTTP 通訊協定來提供給要求使用的其他資訊。Provides access to the HTTP request to access and respond to the additional information made available for requests over the HTTP protocol.

public ref class HttpRequestMessageProperty sealed : System::ServiceModel::Channels::IMessageProperty
public sealed class HttpRequestMessageProperty : System.ServiceModel.Channels.IMessageProperty
type HttpRequestMessageProperty = class
    interface IMessageProperty
Public NotInheritable Class HttpRequestMessageProperty
Implements IMessageProperty
繼承
HttpRequestMessageProperty
實作

範例

下列程式碼會示範如何在這個類別的執行個體內設定幾個屬性,並將此執行個體加入訊息中。The following code shows how to set several of the properties in an instance of this class and incorporate the instance into a message.

static Message BuildMessage()
{
    Message messageToSend = null;
    HttpRequestMessageProperty reqProps = new HttpRequestMessageProperty();
    reqProps.SuppressEntityBody = false;
    reqProps.Headers.Add("CustomHeader", "Test Value");
    reqProps.Headers.Add(HttpRequestHeader.UserAgent, "my user agent");

    try
    {
        messageToSend = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/IUntypedService/ProcessMessage", "Hello WCF");
    }
    catch (Exception e)
    {
        Console.WriteLine("got exception when sending message: " + e.ToString());
    }

    messageToSend.Properties[HttpRequestMessageProperty.Name] = reqProps;
    return messageToSend;
}
Private Shared Function BuildMessage() As Message
    Dim messageToSend As Message = Nothing
    Dim reqProps As New HttpRequestMessageProperty()
    reqProps.SuppressEntityBody = False
    reqProps.Headers.Add("CustomHeader", "Test Value")
    reqProps.Headers.Add(HttpRequestHeader.UserAgent, "my user agent")

    Try
        messageToSend = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/IUntypedService/ProcessMessage", "Hello WCF")
    Catch e As Exception
        Console.WriteLine("got exception when sending message: " & e.ToString())
    End Try

    messageToSend.Properties(HttpRequestMessageProperty.Name) = reqProps
    Return messageToSend
End Function

備註

這是一般用途的類別,可讓開發人員直接存取 HTTP 要求資訊,這些資訊可用於封裝 HTTP 特定的資訊。This is a general-purpose class that gives the developer direct access to the HTTP request information, which can be used for encapsulating HTTP-specific information. 使用這個類別的一個範例就是支援根據代表性狀態傳輸 (REST) 架構所實作的服務。One example of the use of this class is to support services implemented in accordance with the Representational State Transfer (REST) architecture.

這個類別會啟用對以下案例的支援:This class enables support for the following scenarios:

  • 讓用於每一個要求的 HTTP 動詞有所不同。Varies the HTTP verb used for each request.

  • 允許根據要求來設定及查詢 HTTP 標頭 (索引鍵, 值) 組。Allows HTTP header (key, value) pairs to be set and queried by request.

  • 允許為 HTTP 要求指定查詢字串。Allows the query string to be specified for an HTTP request.

這個類別可由 HttpTransportBindingElement 和相關類別使用。This class can be used by HttpTransportBindingElement and related classes.

如果是傳入訊息,這個屬性會加入至訊息中。For incoming messages, this property is added to messages.

如果是傳出訊息,這個屬性會造成以下情況發生:For outgoing messages, this property causes the following to happen:

建構函式

HttpRequestMessageProperty()

初始化 HttpRequestMessageProperty 類別的新執行個體。Initializes a new instance of the HttpRequestMessageProperty class.

屬性

Headers

從 HTTP 要求取得 HTTP 標頭。Gets the HTTP headers from the HTTP request.

Method

取得或設定 HTTP 要求的 HTTP 動詞。Gets or sets the HTTP verb for the HTTP request.

Name

取得與 HttpRequestMessageProperty 類別相關聯之訊息屬性的名稱。Gets the name of the message property associated with the HttpRequestMessageProperty class.

QueryString

取得或設定 HTTP 要求的查詢字串。Gets or sets the query string for the HTTP request.

SuppressEntityBody

取得或設定值,這個值指出是否會忽略訊息的本文以及只傳送標頭。Gets or sets a value that indicates whether the body of the message is ignored and only the headers are sent.

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

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

(繼承來源 Object)
GetType()

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

(繼承來源 Object)
MemberwiseClone()

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

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

明確介面實作

IMessageProperty.CreateCopy()

建立並傳回目前物件的複本。Creates and returns a copy of the current object.

適用於