SoapHeader.DidUnderstand 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示 XML Web services 方法是否已正确处理 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 标头,并要求使用对 MyWebMethod
XML Web 服务方法的任何调用发送该标头。 此外,接收 MyWebMethod
SOAP 标头以外的 MyHeader
任何 SOAP 标头。 对于可以处理的 SOAP 标头 MyWebMethod
, DidUnderstand 设置为 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
。 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.