SoapHeaderAttribute Klasa

Definicja

Ten atrybut jest stosowany do metody usługi sieci Web XML lub klienta usługi sieci Web XML w celu określenia nagłówka SOAP, który może przetworzyć metoda usługi sieci Web XML lub klient usługi sieci Web XML. Klasa ta nie może być dziedziczona.

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
Dziedziczenie
SoapHeaderAttribute
Atrybuty

Przykłady

Następująca MyWebService usługa sieci Web XML definiuje jeden z SoapHeader typów MyHeader. Metoda Hello usługi sieci Web XML wymaga od klienta wywołania metody usługi sieci Web XML za pomocą tej SoapHeadermetody . Usługa Hello sieci Web XML przechwytuje również wszystkie nagłówki PROTOKOŁU SOAP inne niż 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

Uwagi

Podstawowe kroki odbierania i przetwarzania nagłówka protokołu SOAP to:

  1. Utwórz klasę pochodną SoapHeader reprezentującą dane przekazane w nagłówku protokołu SOAP.

  2. Dodaj element członkowski do klasy usługi sieci Web XML lub klasy serwera proxy klienta usługi sieci Web XML typu utworzonego w kroku 1.

  3. SoapHeaderAttribute Zastosuj element do metody usługi sieci Web XML lub odpowiedniej metody w klasie serwera proxy, określając element członkowski utworzony w kroku 2 we MemberName właściwości .

  4. W ramach metody usługi sieci Web XML lub kodu klienta usługi sieci Web XML uzyskaj dostęp do MemberName właściwości w celu przetworzenia danych wysyłanych w nagłówku protokołu SOAP.

Aby uzyskać więcej informacji, zobacz MemberName właściwość .

Konstruktory

SoapHeaderAttribute(String)

Inicjuje SoapHeaderAttribute nowe wystąpienie klasy, ustawiając składową klasy usługi sieci Web XML reprezentującą zawartość nagłówka protokołu SOAP.

Właściwości

Direction

Pobiera lub ustawia, czy nagłówek SOAP jest przeznaczony dla usługi sieci Web XML, czy klienta usługi sieci Web XML, czy obu.

MemberName

Pobiera lub ustawia składową klasy usługi sieci Web XML reprezentującą zawartość nagłówka PROTOKOŁU SOAP.

Required
Nieaktualne.

Ten element członkowski jest przestarzały i nie ma funkcji.

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attributeelementu .

(Odziedziczone po Attribute)

Metody

Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi.

(Odziedziczone po Attribute)
GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

(Odziedziczone po Attribute)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

W przypadku zastąpienia w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

Po przesłonięciu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, który może służyć do pobierania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy

Zobacz też