共用方式為


SoapHeader.DidUnderstand 屬性

定義

取得或設定值,指出 XML Web Service 方法是否已適當地處理 SOAP 標頭。

public:
 property bool DidUnderstand { bool get(); void set(bool value); };
public bool DidUnderstand { get; set; }
member this.DidUnderstand : bool with get, set
Public Property DidUnderstand As Boolean

屬性值

如果 SOAP 標頭已適當地處理,則為 true,否則為 false

範例

下列 MyWebService XML Web 服務會 MyHeader 定義 SOAP 標頭,並要求它與 XML Web 服務方法的任何呼叫 MyWebMethod 一起傳送。 此外,會 MyWebMethod 接收 SOAP 標頭以外的 MyHeader 任何 SOAP 標頭。 對於可以處理的 SOAP 標頭 MyWebMethodDidUnderstand 會設定為 true

<%@ 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",Required=false)]

    public string MyWebMethod() {

       foreach (SoapUnknownHeader header in unknownHeaders) {
           // Perform some processing on the header.
       if (header.Element.Name == "MyKnownHeader")
               header.DidUnderstand = true;
       else
                // For those headers that cannot be  
                // processed, set the DidUnderstand property to false.
                header.DidUnderstand = false;
       }
       return "Hello";
    }
}
<%@ 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 theHeader As MyHeader
    ' Receive all SOAP headers besides the MyHeader SOAP header.
    Public unknownHeaders() As SoapUnknownHeader    

    'Receive any SOAP headers other than MyHeader.    
    <WebMethod, _
     SoapHeader("theHeader", Direction := SoapHeaderDirection.InOut), _
     SoapHeader("unknownHeaders")> _
    Public Function MyWebMethod() As String
                
        Dim header As SoapUnknownHeader
        For Each header In unknownHeaders
            ' Perform some processing on the header.
            If header.Element.Name = "MyKnownHeader" Then
                header.DidUnderstand = True
            Else
                ' For those headers that cannot be
                ' processed, set the DidUnderstand propert to false.
                header.DidUnderstand = False
            End If
        Next header
        Return "Hello"
    End Function
    
End Class

備註

對於 XML Web 服務定義的 SOAP 標頭,ASP.NET 假設 XML Web 服務方法藉由將 的初始值 DidUnderstand 設定為 true ,正確處理 SOAP 標頭。 對於 XML Web 服務未定義的 SOAP 標頭,初始值為 false 。 如果 ASP.NET 偵測到在方法傳回之後已設定 false 為 的 XML Web 服務方法 DidUnderstand 的 SOAP 標頭,則會 SoapHeaderException 擲回 XML Web 服務用戶端,而不是 XML Web 服務方法的結果。

適用於

另請參閱