HttpRequestMessageProperty.Headers Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

        messageToSend = Message.CreateMessage(MessageVersion.Soap11, "", "Hello WCF");
    catch (Exception e)
        Console.WriteLine("got exception when sending message: " + e.ToString());

    messageToSend.Properties[HttpRequestMessageProperty.Name] = reqProps;
    return messageToSend;

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Available since 3.0
Windows Phone Silverlight
Available since 7.0
Return to top