This topic has not yet been rated - Rate this topic

HttpRequestMessageProperty.Headers Property

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Gets the HTTP headers from the HTTP request.

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public WebHeaderCollection Headers { get; }

Property Value

Type: System.Net.WebHeaderCollection
Returns a WebHeaderCollection that contains the HTTP headers in the HTTP request.

There are situations in which this property is not available and attempts to access it may cause an exception. This can happen when WCF is hosted in IIS, after the HTTP request is complete, especially in one-way scenarios where the reply is sent back before the message has become available.

The following code shows how to use this property to add custom headers to 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;
}


.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 8 Release Preview, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)