SoapHeader.DidUnderstand Właściwość
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Pobiera lub ustawia wartość wskazującą, czy metoda usługi sieci Web XML prawidłowo przetworzyła nagłówek 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
Wartość właściwości
true jeśli nagłówek SOAP został prawidłowo przetworzony; w przeciwnym razie false.
Przykłady
Następująca MyWebService usługa sieci Web XML definiuje MyHeader nagłówek SOAP i wymaga wysłania go z dowolnymi wywołaniami metody MyWebMethod usługi sieci Web XML. Ponadto otrzymuje MyWebMethod wszystkie nagłówki PROTOKOŁU SOAP inne niż MyHeader nagłówek PROTOKOŁU SOAP. W przypadku nagłówków PROTOKOŁU SOAP, które MyWebMethod mogą przetwarzać, DidUnderstand ustawiono wartość 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
Uwagi
W przypadku nagłówków PROTOKOŁU SOAP zdefiniowanych przez usługę sieci Web XML ASP.NET zakłada, że metoda usługi sieci Web XML prawidłowo przetworzyła nagłówek SOAP, ustawiając początkową wartość na DidUnderstand true. W przypadku nagłówków PROTOKOŁU SOAP, które nie są zdefiniowane przez usługę sieci Web XML, początkowa wartość to false. Jeśli ASP.NET wykryje nagłówki PROTOKOŁU SOAP przekazane do metody usługi sieci Web XML ustawione DidUnderstand na false wartość po powrocie metody, SoapHeaderException element zostanie zwrócony z powrotem do klienta usługi sieci Web XML zamiast wyników z metody usługi sieci Web XML.