System.Web.Services.Protoco ...


SoapHeaderAttribute (Clase)
Este atributo se aplica a un método de servicios Web XML o a un cliente de servicios Web XML para especificar un encabezado SOAP que el método o el cliente de servicios Web XML puede procesar. No se puede heredar esta clase.

Espacio de nombres: System.Web.Services.Protocols
Ensamblado: System.Web.Services (en system.web.services.dll)

Sintaxis

Visual Basic (Declaración)
<AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple:=True)> _
Public NotInheritable Class SoapHeaderAttribute
    Inherits Attribute
Visual Basic (Uso)
Dim instance As SoapHeaderAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple=true)] 
public sealed class SoapHeaderAttribute : Attribute
C++
[AttributeUsageAttribute(AttributeTargets::Method, AllowMultiple=true)] 
public ref class SoapHeaderAttribute sealed : public Attribute
J#
/** @attribute AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple=true) */ 
public final class SoapHeaderAttribute extends Attribute
JScript
AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple=true) 
public final class SoapHeaderAttribute extends Attribute
XAML
No aplicable.
Comentarios

Los pasos básicos para recibir y procesar un encabezado SOAP son los siguientes:

  1. Cree una clase derivada de SoapHeader que represente los datos pasados al encabezado SOAP.

  2. Agregue un miembro a la clase de servicios Web XML o a la clase de proxy cliente de servicios Web XML; el miembro debe ser del mismo tipo que el creado en el primer paso.

  3. Aplique SoapHeaderAttribute al método de servicios Web XML o al método correspondiente de la clase de proxy, especificando el miembro creado en el segundo paso en la propiedad MemberName.

  4. Dentro del método de servicios Web XML o del código de cliente de servicios Web XML, obtenga acceso a la propiedad MemberName para procesar los datos enviados en el encabezado SOAP.

Para obtener más detalles, vea la propiedad MemberName.

Ejemplo

El siguiente servicio Web XML MyWebService define un SoapHeader de tipo MyHeader. El método de servicios Web XML Hello requiere que el cliente invoque un método de servicios Web XML con este SoapHeader. El servicio Web XML Hello también detecta los encabezados SOAP que sean distintos de MyHeader.

Visual Basic
<%@ 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
C#
<%@ 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;
       }
    }
}
Jerarquía de herencia

System.Object
   System.Attribute
    System.Web.Services.Protocols.SoapHeaderAttribute
Seguridad para subprocesos

Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Plataformas

Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

Información de versión

.NET Framework

Compatible con: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Compatible con: 2.0, 1.0
Vea también

Page view tracker