SoapHeader.DidUnderstand 属性

定义

获取或设置一个值,该值指示 XML Web services 方法是否已正确处理 SOAP 标头。Gets or sets a value indicating whether an XML Web service method properly processed a SOAP header.

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;否则为 falsetrue if the SOAP header was properly processed; otherwise false.

示例

下面MyWebService的 XML Web service MyHeader定义 SOAP 标头, 并要求它与对 XML Web service 方法的MyWebMethod任何调用一起发送。The following MyWebService XML Web service defines the MyHeader SOAP header and requires it to be sent with any calls to the MyWebMethod XML Web service method. 此外, MyWebMethod还会接收MyHeader soap 标头以外的任何 soap 标头。Additionally, the MyWebMethod receives any SOAP headers other than the MyHeader SOAP header. 对于MyWebMethod可以处理的 SOAP 标头DidUnderstand , 将设置true为。For SOAP headers that MyWebMethod can process, DidUnderstand is set to 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 service 定义的 soap 标头, ASP.NET 假定 XML Web service 方法通过将的DidUnderstand初始值设置为true, 正确处理 SOAP 标头。For SOAP headers defined by an XML Web service, ASP.NET assumes the XML Web service method properly processed the SOAP header by setting the initial value of DidUnderstand to true. 对于 XML Web service 未定义的 SOAP 标头, 初始值为falseFor SOAP headers not defined by the XML Web service, the initial value is false. 如果 ASP.NET 检测到在方法返回后传递到 XML Web service DidUnderstand方法的false SOAP 标头, 并将SoapHeaderException其设置为, 则会将返回到 XML Web service 客户端, 而不是 XML Web service 方法的结果。If ASP.NET detects SOAP headers passed to an XML Web service method with DidUnderstand set to false after the method returns, a SoapHeaderException is thrown back to the XML Web service client instead of the results from the XML Web service method.

适用于

另请参阅