SoapUnknownHeader Class

Definition

Represents the data received from a SOAP header that was not understood by the recipient XML Web service or XML Web service client. This class cannot be inherited.

public ref class SoapUnknownHeader sealed : System::Web::Services::Protocols::SoapHeader
public sealed class SoapUnknownHeader : System.Web.Services.Protocols.SoapHeader
type SoapUnknownHeader = class
    inherit SoapHeader
Public NotInheritable Class SoapUnknownHeader
Inherits SoapHeader
Inheritance
SoapUnknownHeader

Examples

The MyWebService XML Web service accepts and processes the MyHeader SOAP header 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;
 
    [WebMethod]
    [SoapHeader("myHeader", Direction=SoapHeaderDirection.InOut)]

    //Receive any SOAP headers other than MyHeader.
    [SoapHeader("unknownHeaders")]

    public string MyWebMethod() {

    string unknownHeaderAttributes = String.Empty;

        // Set myHeader.MyValue to some value.
         
       foreach (SoapUnknownHeader header in unknownHeaders) {
           // Perform some processing on the header.
           foreach (XmlAttribute attribute in header.Element.Attributes) {
              unknownHeaderAttributes = unknownHeaderAttributes + attribute.Name + ":" + attribute.Value + ";";            
           }
           // For those headers that cannot be 
           // processed, set the DidUnderstand property to false.
           header.DidUnderstand = false;
       }
       return unknownHeaderAttributes;
    }
}
<%@ WebService Language="VB" Class="MyWebService"%>
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml
Imports System

' Define a SOAP header by deriving from the SoapHeader base class.
Public Class MyHeader
    Inherits SoapHeader
    Public MyValue As String
End Class

Public Class MyWebService
    
    Public myHeader As MyHeader
    
    ' Receive all SOAP headers besides the MyHeader SOAP header.
    Public unknownHeaders() As SoapUnknownHeader    

    'Receive any SOAP headers other than MyHeader.
    <WebMethod, _
    SoapHeader("myHeader", Direction := SoapHeaderDirection.InOut), _
    SoapHeader("unknownHeaders")> _
    Public Function MyWebMethod() As String
        Dim unknownHeaderAttributes As String = String.Empty
        
        ' Set myHeader.MyValue to some value.
        Dim header As SoapUnknownHeader
        For Each header In  unknownHeaders
            ' Perform some processing on the header.
            Dim attribute As XmlAttribute
            For Each attribute In header.Element.Attributes
                unknownHeaderAttributes &= attribute.Name & ":" & _
                    attribute.Value & ";"
            Next attribute
            ' For those headers that cannot be 
            ' processed, set the DidUnderstand property to false.
            header.DidUnderstand = False
        Next header
        
        Return unknownHeaderAttributes
        
    End Function
End Class

Remarks

A SOAP client might invoke an XML Web service with additional data beyond the required parameters in the form of a SOAP header. An XML Web service created using ASP.NET or an XML Web service client can view any SOAP headers it did not know about at the time the XML Web service was written by applying a SoapHeaderAttribute with a MemberName property of either an array of SoapHeader, SoapHeader, SoapUnknownHeader or an array of SoapUnknownHeader to the XML Web service method. Specifying a Type of SoapUnknownHeader, allows the XML Web service to view the contents of the SOAP header in the form of an XmlElement.

Constructors

SoapUnknownHeader()

Initializes a new instance of the SoapUnknownHeader class.

Properties

Actor

Gets or sets the recipient of the SOAP header.

(Inherited from SoapHeader)
DidUnderstand

Gets or sets a value indicating whether an XML Web service method properly processed a SOAP header.

(Inherited from SoapHeader)
Element

Gets or sets the XML Header element for a SOAP request or response.

EncodedMustUnderstand

Gets or sets the value of the mustUnderstand XML attribute for the SOAP header when communicating with SOAP protocol version 1.1.

(Inherited from SoapHeader)
EncodedMustUnderstand12

Gets or sets the value of the mustUnderstand XML attribute for the SOAP header when communicating with SOAP protocol version 1.2.

(Inherited from SoapHeader)
EncodedRelay

Gets or sets the relay attribute of the SOAP 1.2 header.

(Inherited from SoapHeader)
MustUnderstand

Gets or sets a value indicating whether the SoapHeader must be understood.

(Inherited from SoapHeader)
Relay

Gets 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.

(Inherited from SoapHeader)
Role

Gets or sets the recipient of the SOAP header.

(Inherited from SoapHeader)

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also