共用方式為


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 Service 必須適當地解譯和處理 SoapHeader,則為 true,否則,即為 false。 預設為 false

範例

下列 XML Web 服務用戶端會定義 類型的 MyHeader 自訂 SOAP 標頭、將 MustUnderstand 屬性設定為 true ,並叫用 MyWebMethod XML Web 服務方法。 如果 XML Web 服務方法未將 SOAP 標頭的 MyHeader 屬性設定 DidUnderstandtrueSoapHeaderException 則會擲回 。

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 為 時,XML Web 服務方法必須將 屬性 true 設定 DidUnderstand 為 ;否則, SoapHeaderException 會透過 ASP.NET 擲回 XML Web 服務用戶端。

EncodedMustUnderstand雖然 和 MustUnderstand 屬性都可以用來設定 SOAP 標頭內屬性的值 mustUnderstand ,但是 MustUnderstand 屬性可讓您使用布林值來設定屬性。

如需將 SOAP 標頭新增至用戶端的詳細資訊,請參閱 使用 SOAP 標頭

適用於

另請參閱