SoapHeader 类

定义

当在派生类中被重写时,表示 SOAP 标头的内容。When overridden in a derived class, represents the content of a SOAP header.

public ref class SoapHeader abstract
public abstract class SoapHeader
type SoapHeader = class
Public MustInherit Class SoapHeader
继承
SoapHeader
派生

示例

下面MyWebService的 XML Web service MyHeader定义 SOAP 标头, 并要求它与对 XML Web service 方法的MyWebMethod任何调用一起发送。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. 此外, MyWebMethod还会接收 soap 标头以外MyHeader的任何 soap 标头。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",Required=false)]

    public string MyWebMethod() {

       foreach (SoapUnknownHeader header in unknownHeaders) {
           // Perform some processing on the header.
       if (header.Element.Name == "MyKnownHeader")
               header.DidUnderstand = true;
       else
                // For those headers that cannot be  
                // processed, set the DidUnderstand property to false.
                header.DidUnderstand = false;
       }
       return "Hello";
    }
}
<%@ 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 theHeader As MyHeader
    ' Receive all SOAP headers besides the MyHeader SOAP header.
    Public unknownHeaders() As SoapUnknownHeader    

    'Receive any SOAP headers other than MyHeader.    
    <WebMethod, _
     SoapHeader("theHeader", Direction := SoapHeaderDirection.InOut), _
     SoapHeader("unknownHeaders")> _
    Public Function MyWebMethod() As String
                
        Dim header As SoapUnknownHeader
        For Each header In unknownHeaders
            ' Perform some processing on the header.
            If header.Element.Name = "MyKnownHeader" Then
                header.DidUnderstand = True
            Else
                ' For those headers that cannot be
                ' processed, set the DidUnderstand propert to false.
                header.DidUnderstand = False
            End If
        Next header
        Return "Hello"
    End Function
    
End Class

注解

如果数据与 XML Web service 方法的主要功能无关, 则 SOAP 标头提供一种方法, 用于将数据传入和向 XML Web service 方法传递数据。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. 例如, XML Web service 可能包含若干 XML Web service 方法, 每个方法都需要自定义身份验证方案。For instance, an XML Web service might contain several XML Web service methods that each require a custom authentication scheme. 不是将参数添加到自定义身份验证方案的每个 XML Web service SoapHeaderAttribute方法, 而是引用SoapHeader派生自的类, 可应用于每个 XML Web service 方法。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. 派生自的类的实现SoapHeader处理自定义的身份验证方案。The implementation for the class deriving from SoapHeader handles the custom authentication scheme. 通过这种方式, XML Web service 方法仅实现特定于该方法的功能, 并使用 SOAP 标头添加附加功能。In this manner, the XML Web service method implements only the functionality specific to it and adds additional functionality using a SOAP header.

以下列表概述了接收和处理 SOAP 标头的基本步骤:The following list outlines the basic steps to receiving and processing a SOAP header:

  1. 创建一个派生自SoapHeader的类, 该类表示传入 SOAP 标头的数据。Create a class that derives from SoapHeader representing the data passed into the SOAP header.

  2. 向实现第一步中创建的类型的 XML Web service 或 XML Web service 客户端代理类的类添加成员。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. 将应用MemberName到代理类中的 XML Web service 方法或相应方法, 并指定在属性的第二步中创建的成员。 SoapHeaderAttributeApply 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. 在 XML Web service 方法或 XML Web service 客户端代码中, 访问MemberName属性来处理 SOAP 标头中发送的数据。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.

构造函数

SoapHeader()

初始化 SoapHeader 类的新实例。Initializes a new instance of the SoapHeader class.

属性

Actor

获取或设置 SOAP 标头的接收者。Gets or sets the recipient of the SOAP header.

DidUnderstand

获取或设置一个值,该值指示 XML Web services 方法是否已正确处理 SOAP 标头。Gets or sets a value indicating whether an XML Web service method properly processed a SOAP header.

EncodedMustUnderstand

当与 SOAP 协议 1.1 版通信时,获取或设置 SOAP 标头的 mustUnderstand XML 特性值。Gets or sets the value of the mustUnderstand XML attribute for the SOAP header when communicating with SOAP protocol version 1.1.

EncodedMustUnderstand12

与 SOAP 协议 1.2 版通信时,获取或设置 SOAP 标头的 mustUnderstand XML 属性的值。Gets or sets the value of the mustUnderstand XML attribute for the SOAP header when communicating with SOAP protocol version 1.2.

EncodedRelay

获取或设置 SOAP 1.2 标头的中转特性。Gets or sets the relay attribute of the SOAP 1.2 header.

MustUnderstand

获取或设置一个值,该值指示是否必须理解 SoapHeaderGets or sets a value indicating whether the SoapHeader must be understood.

Relay

获取或设置一个值,该值指示当前节点不理解 SOAP 标头时是否将该标头中转到下一个 SOAP 节点。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.

Role

获取或设置 SOAP 标头的接收者。Gets or sets the recipient of the SOAP header.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅