HttpRequestMessageProperty.Headers Proprietà

Definizione

Ottiene le intestazioni HTTP dalla richiesta HTTP.

public:
 property System::Net::WebHeaderCollection ^ Headers { System::Net::WebHeaderCollection ^ get(); };
public System.Net.WebHeaderCollection Headers { get; }
member this.Headers : System.Net.WebHeaderCollection
Public ReadOnly Property Headers As WebHeaderCollection

Valore della proprietà

WebHeaderCollection

Restituisce WebHeaderCollection che contiene le intestazioni HTTP nella richiesta HTTP.

Esempio

Nel seguente codice viene illustrato come utilizzare questa proprietà per aggiungere intestazioni personalizzate a un messaggio.

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

Commenti

In alcune situazioni questa proprietà non è disponibile e i tentativi per accedervi possono causare la generazione di un'eccezione. Ciò può verificarsi quando WCF è ospitato in IIS, al termine della richiesta HTTP, in particolare negli scenari unidirezionale in cui la risposta viene inviata prima che il messaggio diventi disponibile.

Si applica a