This documentation is archived and is not being maintained.

SoapHeader Class

When overridden in a derived class, represents the content of a SOAP header.

Namespace:  System.Web.Services.Protocols
Assembly:  System.Web.Services (in System.Web.Services.dll)

public abstract class SoapHeader

The SoapHeader type exposes the following members.

Protected methodSoapHeaderInitializes a new instance of the SoapHeader class.

Public propertyActorGets or sets the recipient of the SOAP header.
Public propertyDidUnderstandGets or sets a value indicating whether an XML Web service method properly processed a SOAP header.
Public propertyEncodedMustUnderstandGets or sets the value of the mustUnderstand XML attribute for the SOAP header when communicating with SOAP protocol version 1.1.
Public propertyEncodedMustUnderstand12Gets or sets the value of the mustUnderstand XML attribute for the SOAP header when communicating with SOAP protocol version 1.2.
Public propertyEncodedRelayGets or sets the relay attribute of the SOAP 1.2 header.
Public propertyMustUnderstandGets or sets a value indicating whether the SoapHeader must be understood.
Public propertyRelayGets or sets a value that indicates whether the SOAP header is to be relayed to the next SOAP node if the current node does not understand the header.
Public propertyRoleGets or sets the recipient of the SOAP header.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

SOAP headers offer a method for passing data to and from an XML Web service method if the data is not directly related to the XML Web service method's primary functionality. For instance, an XML Web service might contain several XML Web service methods that each require a custom authentication scheme. Instead of adding parameters to each XML Web service method for the custom authentication scheme, a SoapHeaderAttribute, referring to a class deriving from SoapHeader, can be applied to each XML Web service method. The implementation for the class deriving from SoapHeader handles the custom authentication scheme. In this manner, the XML Web service method implements only the functionality specific to it and adds additional functionality using a SOAP header.

The following list outlines the basic steps to receiving and processing a SOAP header:

  1. Create a class that derives from SoapHeader representing the data passed into the SOAP header.

  2. Add a member to the class implementing an XML Web service or an XML Web service client proxy class, of the type created in the first step.

  3. Apply a SoapHeaderAttribute to the XML Web service method or the corresponding method in the proxy class, specifying the member created in the second step in the MemberName property.

  4. Within the XML Web service method or XML Web service client code, access the MemberName property to process the data sent in the SOAP header.

The following MyWebService XML Web service defines the MyHeader SOAP header and requires it to be sent with any calls to the MyWebMethod XML Web service method. Additionally, MyWebMethod receives any SOAP headers other than the MyHeader SOAP header.

<%@ WebService Language="C#" Class="MyWebService"%>
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using System;

// Define a SOAP header by deriving from the SoapHeader base class.

public class MyHeader : SoapHeader {
    public string MyValue;

public class MyWebService {

    public MyHeader myHeader;
    // Receive all SOAP headers besides the MyHeader SOAP header.
    public SoapUnknownHeader[] unknownHeaders;

    [SoapHeader("myHeader", Direction=SoapHeaderDirection.InOut)]

    //Receive any SOAP headers other than MyHeader.

    public string MyWebMethod() {

       foreach (SoapUnknownHeader header in unknownHeaders) {
           // Perform some processing on the header.
       if (header.Element.Name == "MyKnownHeader")
               header.DidUnderstand = true;
                // For those headers that cannot be  
                // processed, set the DidUnderstand property to false.
                header.DidUnderstand = false;
       return "Hello";

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.