SoapHeader.MustUnderstand 属性

定义

获取或设置一个值,该值指示是否必须理解 SoapHeader

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

属性值

Boolean

如果 XML Web services 必须正确解释和处理 SoapHeader,则为 true;否则为 false。 默认值为 false

示例

以下 XML Web 服务客户端定义类型的 MyHeader自定义 SOAP 标头,将 MustUnderstand 属性设置为 true并调用 MyWebMethod XML Web 服务方法。 如果 XML Web 服务方法未将 DidUnderstand SOAP 标头的属性 MyHeader 设置为 true,则会引发 a SoapHeaderException

int main()
{
   MyWebService^ ws = gcnew MyWebService;
   try
   {
      MyHeader^ customHeader = gcnew MyHeader;
      customHeader->MyValue = "Header Value for MyValue";
      customHeader->MustUnderstand = true;
      ws->myHeader = customHeader;
      int results = ws->MyWebMethod( 3, 5 );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception: {0}", e );
   }

}
using System;

public class Sample {

    public static void Main() {
        MyWebService ws = new MyWebService();

        try {
            MyHeader customHeader = new MyHeader();
            customHeader.MyValue = "Header Value for MyValue";
            customHeader.MustUnderstand = true;
            ws.myHeader = customHeader;

        int results = ws.MyWebMethod(3,5);
        }
        catch (Exception e) {
            Console.WriteLine ("Exception: {0}", e.ToString());
        }
    }
}
Public Class Sample
    
    Public Shared Sub Main()
        Dim ws As New MyWebService()

        Try
            Dim customHeader As New MyHeader1()

            customHeader.MyValue = "Header Value for MyValue"
            customHeader.MustUnderstand = True

            ws.myHeader = customHeader

        Dim results As Integer

            results = ws.MyWebMethod(3,5)
        Catch e As Exception
            Console.WriteLine("Exception: {0}", e.ToString())
        End Try
    End Sub
End Class

注解

当 XML Web 服务客户端将 SOAP 标头添加到 XML Web 服务方法调用时,该MustUnderstand属性true必须设置为 trueDidUnderstand XML Web 服务方法,否则SoapHeaderException,ASP.NET 将 XML Web 服务客户端抛回 XML Web 服务客户端。

EncodedMustUnderstand MustUnderstand尽管属性和属性都可用于在 SOAP 标头中设置属性的值mustUnderstand,但该MustUnderstand属性允许你使用布尔值设置属性。

有关将 SOAP 标头添加到客户端的详细信息,请参阅 “使用 SOAP 标头”。

适用于

另请参阅