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.

public:
 SoapHeaderAttribute(System::String ^ memberName);
public SoapHeaderAttribute (string memberName);
new System.Web.Services.Protocols.SoapHeaderAttribute : string -> System.Web.Services.Protocols.SoapHeaderAttribute
Public Sub New (memberName As String)

参数

memberName
String

表示 SOAP 标头内容的 XML Web services 类的成员。The member of the XML Web service class representing the SOAP header contents. MemberName 属性将被设置为此参数的值。The MemberName property will be set to the value of this parameter.

示例

下面MyWebService的 XML Web service 定义一个SoapHeader类型MyHeader为的。The following MyWebService XML Web service defines one SoapHeader of type MyHeader. XML Web service 方法将myHeader成员指定为MemberName属性, 以接收传入 XML Web service 方法的MyHeader SOAP 标头的内容。 HelloThe Hello XML Web service method specifies the myHeader member as the MemberName property to receive the contents of MyHeader SOAP headers passed into the XML Web service method.

#using <System.EnterpriseServices.dll>
#using <System.Web.Services.dll>

using namespace System;
using namespace System::Web::Services;
using namespace System::Web::Services::Protocols;

// Define a SOAP header by deriving from the SoapHeader base class.
// The header contains just one string value.
public ref class MyHeader: public SoapHeader
{
public:
   String^ MyValue;
};

public ref class MyWebService
{
public:

   // Member variable to receive the contents of the MyHeader SOAP header.
   MyHeader^ myHeader;

   [WebMethod]
   [SoapHeader("myHeader",Direction=SoapHeaderDirection::InOut)]
   void Hello(){}

};

using System;
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 SOAP header.
    public MyHeader myHeader;
 
    [WebMethod]
    [SoapHeader("myHeader", Direction=SoapHeaderDirection.InOut)]
    public void Hello() {
    }
}
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 SOAP header.
   Public myHeader As MyHeader

   
   <WebMethod, _ 
    SoapHeader("myHeader", Direction := SoapHeaderDirection.InOut)> _
   Public Sub Hello()

   End Sub
End Class

注解

XML Web service 客户端或 XML Web service 可以通过将应用SoapHeaderAttribute于 XML Web service 类中的 XML Web service 方法或代理类中的相应方法, 指定它要处理的特定 XML Web service 方法的 SOAP 标头。An XML Web service client or XML Web service can specify the SOAP headers it wants to process for specific XML Web service methods by applying a SoapHeaderAttribute to the XML Web service method in the XML Web service class or the corresponding method in the proxy class. 为了使 XML Web service 方法接收 SOAP 标头的内容, 将向Type派生自的派生自SoapHeader的 XML Web service 类添加成员。In order for the XML Web service method to receive the contents of the SOAP header, a member is added to the XML Web service class of a Type derived from SoapHeader. 同样, XML Web service 客户端将成员添加到从SoapHeader派生的代理类。Likewise, an XML Web service client adds a member to the proxy class deriving from SoapHeader. Type派生自SoapHeader的表示 SOAP 标头的内容, 由 XML Web service 的开发人员创建或想要接收 SOAP 标头的 XML Web service 客户端创建。That Type deriving from SoapHeader represents the contents of the SOAP header and is created by the developer of the XML Web service or XML Web service client that wants to receive the SOAP header. 创建类后, SoapHeaderAttribute可以应用于 XML Web service 客户端代理类中的 XML Web service 方法或相应方法, 指定成员以接收带有此构造函数的memberName参数的 SOAP 标头内容。MemberName或属性。Once the class is created, a SoapHeaderAttribute can be applied to the XML Web service method or corresponding method in the XML Web service client proxy class specifying the member to receive the SOAP header contents with the memberName parameter to this constructor or the MemberName property.

XML Web service 方法可以通过将多个成员添加到 XML Web service 类或 XML Web service 代理类, 然后将多个SoapHeaderAttribute属性应用于 XML Web service 方法来接收多个 SOAP 标头。An XML Web service method can receive multiple SOAP headers by adding multiple members to the XML Web service class or the XML Web service proxy class and in turn applying multiple SoapHeaderAttribute attributes to the XML Web service method.

若要在写入 XML Web service 时接收和处理未知Type的 SOAP 标头, 请将成员SoapUnknownHeader SoapHeader的指定为或任一类的数组。To receive and process unknown SOAP headers at the time the XML Web service is written, specify the Type of the member to be either SoapUnknownHeader, SoapHeader or an array of either class.

适用于