次の方法で共有


SoapUnknownHeader.Element プロパティ

SOAP 要求または SOAP 応答の XML ヘッダー要素を取得または設定します。

Public Property Element As XmlElement
[C#]
public XmlElement Element {get; set;}
[C++]
public: __property XmlElement* get_Element();public: __property void set_Element(XmlElement*);
[JScript]
public function get Element() : XmlElement;public function set Element(XmlElement);

プロパティ値

SOAP ヘッダーの生の XML を表す XmlElement

解説

XML Web サービス メソッドが、XML Web サービスの書き込み時には不明だった SOAP ヘッダーを処理する場合は、その SOAP ヘッダーの生の XML を表す XmlElement クラスを処理できます。

使用例

[Visual Basic, C#] 認識している MyHeader SOAP ヘッダー以外のヘッダーを含めたすべての SOAP ヘッダーを受け取る MyWebService XML Web サービスを次に示します。 MyWebMethod XML Web サービス メソッドは、文字列として渡された最後の不明な SOAP ヘッダーの XML 属性をクライアントに返します。

 
<%@ 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 myHeader As MyHeader
    
    ' Receive all SOAP headers besides the MyHeader SOAP header.
    Public unknownHeaders() As SoapUnknownHeader    

    'Receive any SOAP headers other than MyHeader.
    <WebMethod, _
    SoapHeader("myHeader", Direction := SoapHeaderDirection.InOut), _
    SoapHeader("unknownHeaders")> _
    Public Function MyWebMethod() As String
        Dim unknownHeaderAttributes As String = String.Empty
        
        ' Set myHeader.MyValue to some value.
        Dim header As SoapUnknownHeader
        For Each header In  unknownHeaders
            ' Perform some processing on the header.
            Dim attribute As XmlAttribute
            For Each attribute In header.Element.Attributes
                unknownHeaderAttributes &= attribute.Name & ":" & _
                    attribute.Value & ";"
            Next attribute
            ' For those headers that cannot be 
            ' processed, set the DidUnderstand property to false.
            header.DidUnderstand = False
        Next header
        
        Return unknownHeaderAttributes
        
    End Function
End Class


[C#] 
<%@ 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")]

    public string MyWebMethod() {

    string unknownHeaderAttributes = String.Empty;

        // Set myHeader.MyValue to some value.
         
       foreach (SoapUnknownHeader header in unknownHeaders) {
           // Perform some processing on the header.
           foreach (XmlAttribute attribute in header.Element.Attributes) {
              unknownHeaderAttributes = unknownHeaderAttributes + attribute.Name + ":" + attribute.Value + ";";            
           }
           // For those headers that cannot be 
           // processed, set the DidUnderstand property to false.
           header.DidUnderstand = false;
       }
       return unknownHeaderAttributes;
    }
}

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

SoapUnknownHeader クラス | SoapUnknownHeader メンバ | System.Web.Services.Protocols 名前空間 | XmlElement | SoapHeaderAttribute