SoapHeaderAttribute 类
定义
此特性应用于 XML Web services 方法或 XML Web services 客户端,用以指定该 XML Web services 方法或 XML Web services 客户端可以处理的 SOAP 标头。This attribute is applied to an XML Web service method or an XML Web service client to specify a SOAP header that the XML Web service method or XML Web service client can process. 此类不能被继承。This class cannot be inherited.
public ref class SoapHeaderAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true)]
public sealed class SoapHeaderAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)]
public sealed class SoapHeaderAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true)>]
type SoapHeaderAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)>]
type SoapHeaderAttribute = class
inherit Attribute
Public NotInheritable Class SoapHeaderAttribute
Inherits Attribute
- 继承
- 属性
示例
下面的 MyWebService XML Web service 定义一个 SoapHeader 类型为的 MyHeader 。The following MyWebService XML Web service defines one SoapHeader of type MyHeader. HelloXML Web service 方法要求客户端通过此调用 XML Web service 方法 SoapHeader 。The Hello XML Web service method requires the client to invoke the XML Web service method with this SoapHeader. HelloXML Web service 还会捕获除之外的任何 SOAP 标头 MyHeader 。The Hello XML Web service also catches any SOAP headers other than MyHeader.
<%@ WebService Language="C#" Class="MyWebService"%>
using System.Web.Services;
using System.Web.Services.Protocols;
// Define a SOAP header by deriving from the SoapHeader base class.
// The header contains just one string value.
public class MyHeader : SoapHeader {
public string MyValue;
}
public class MyWebService {
// Member variable to receive the contents of the MyHeader SoapHeader.
public MyHeader myHeader;
// Member variable to receive all headers other than MyHeader.
public SoapUnknownHeader[] unknownHeaders;
[WebMethod]
[SoapHeader("myHeader", Direction=SoapHeaderDirection.InOut)]
// Receive any SOAP headers other than MyHeader.
[SoapHeader("unknownHeaders")]
public void Hello() {
// Process the MyHeader SoapHeader.
if (myHeader.MyValue == "Some string") {
// Process the header.
}
foreach (SoapHeader header in unknownHeaders) {
// Perform some processing on header.
// For those headers that cannot be processed,
// set the DidUnderstand property to false.
header.DidUnderstand = false;
}
}
}
<%@ WebService Language="VB" Class="MyWebService"%>
Imports System.Web.Services
Imports System.Web.Services.Protocols
' Define a SOAP header by deriving from the SoapHeader base class.
' The header contains just one string value.
Public Class MyHeader
Inherits SoapHeader
Public MyValue As String
End Class
Public Class MyWebService
' Member variable to receive the contents of the MyHeader SoapHeader.
Public myHeader As MyHeader
' Member variable to receive all headers other than MyHeader.
Public unknownHeaders() As SoapUnknownHeader
' Receive any SOAP headers other than MyHeader.
<WebMethod, _
SoapHeader("myHeader", Direction := SoapHeaderDirection.InOut), _
SoapHeader("unknownHeaders")> _
Public Sub Hello()
' Process the MyHeader SoapHeader.
If myHeader.MyValue = "Some string" Then
' Process the header.
End If
Dim header As SoapHeader
For Each header In unknownHeaders
' Perform some processing on header
' For those headers that cannot be processed,
' set the DidUnderstand to false.
header.DidUnderstand = False
Next header
End Sub
End Class
注解
接收和处理 SOAP 标头的基本步骤如下:The basic steps to receiving and processing a SOAP header are:
创建一个派生自的类 SoapHeader ,该类表示在 SOAP 标头中传递的数据。Create a class deriving from SoapHeader representing the data passed in the SOAP header.
将成员添加到 XML Web service 类或在步骤1中创建的类型的客户端代理类 XML Web service。Add a member to the XML Web service class or XML Web service client proxy class of the type created in step 1.
将应用 SoapHeaderAttribute 到代理类中的 XML Web service 方法或相应方法,并指定在属性中的步骤2中创建的成员 MemberName 。Apply a SoapHeaderAttribute to the XML Web service method or the corresponding method in the proxy class, specifying the member created in step 2 in the MemberName property.
在 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.
有关更多详细信息,请参见 MemberName 属性。For more details, see the MemberName property.
构造函数
| SoapHeaderAttribute(String) |
通过设置表示 SOAP 标头内容的 XML Web services 类的成员,初始化 SoapHeaderAttribute 类的新实例。Initializes a new instance of the SoapHeaderAttribute class, setting the member of the XML Web service class representing the SOAP header contents. |
属性
| Direction |
获取或设置 SOAP 标头是用于 XML Web services 还是 XML Web services 客户端,或同时用于二者。Gets or sets whether the SOAP header is intended for the XML Web service or the XML Web service client or both. |
| MemberName |
获取或设置表示 SOAP 标头内容的 XML Web services 类的成员。Gets or sets the member of the XML Web service class representing the SOAP header contents. |
| Required |
已过时。
此成员已经过时,不具有任何功能。This member is obsolete and has no functionality. |
| TypeId |
在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute. (继承自 Attribute) |
方法
| Equals(Object) |
返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object. (继承自 Attribute) |
| GetHashCode() |
返回此实例的哈希代码。Returns the hash code for this instance. (继承自 Attribute) |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| IsDefaultAttribute() |
在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (继承自 Attribute) |
| Match(Object) |
当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (继承自 Attribute) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |
显式接口实现
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers. (继承自 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface. (继承自 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1). (继承自 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object. (继承自 Attribute) |