Bagikan melalui


MessageHeaderAttribute.MustUnderstand Properti

Definisi

Menentukan apakah simpul yang bertindak dalam Actor peran harus memahami header ini. Ini dipetakan ke mustUnderstand atribut header SOAP.

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

Nilai Properti

true jika simpul yang bertindak dalam Actor peran harus memahami header ini; jika tidak, false.

Contoh

Contoh kode berikut menunjukkan penggunaan MessageHeaderAttribute untuk membuat header SOAP untuk pesan respons dengan Nameproperti , Namespace dan MustUnderstand diatur ke nilai yang sesuai untuk header ini. Contoh kode diikuti dengan contoh pesan saat dikirim.

 [MessageContract]
 public class HelloResponseMessage
 {
   private string localResponse = String.Empty;
   private string extra = String.Empty;

   [MessageBodyMember(
     Name = "ResponseToGreeting",
     Namespace = "http://www.examples.com")]
   public string Response
   {
     get { return localResponse; }
     set { localResponse = value; }
   }

   [MessageHeader(
     Name = "OutOfBandData",
     Namespace = "http://www.examples.com",
     MustUnderstand=true
   )]
   public string ExtraValues
   {
     get { return extra; }
     set { this.extra = value; }
  }

  /*
   The following is the response message, edited for clarity.

   <s:Envelope>
     <s:Header>
       <a:Action s:mustUnderstand="1">http://HelloResponseMessage/Action</a:Action>
       <h:OutOfBandData s:mustUnderstand="1" xmlns:h="http://www.examples.com">Served by object 13804354.</h:OutOfBandData>
     </s:Header>
     <s:Body>
       <HelloResponseMessage xmlns="Microsoft.WCF.Documentation">
         <ResponseToGreeting xmlns="http://www.examples.com">Service received: Hello.</ResponseToGreeting>
       </HelloResponseMessage>
     </s:Body>
   </s:Envelope>
   */
}
  <MessageContract> _
  Public Class HelloResponseMessage
    Private localResponse As String = String.Empty
    Private extra As String = String.Empty

    <MessageBodyMember(Name := "ResponseToGreeting", Namespace := "http://www.examples.com")> _
    Public Property Response() As String
      Get
          Return localResponse
      End Get
      Set(ByVal value As String)
          localResponse = value
      End Set
    End Property

    <MessageHeader(Name := "OutOfBandData", Namespace := "http://www.examples.com", MustUnderstand:=True)> _
    Public Property ExtraValues() As String
      Get
          Return extra
      End Get
      Set(ByVal value As String)
          Me.extra = value
      End Set
    End Property

'   
'    The following is the response message, edited for clarity.
'    
'    <s:Envelope>
'      <s:Header>
'        <a:Action s:mustUnderstand="1">http://HelloResponseMessage/Action</a:Action>
'        <h:OutOfBandData s:mustUnderstand="1" xmlns:h="http://www.examples.com">Served by object 13804354.</h:OutOfBandData>
'      </s:Header>
'      <s:Body>
'        <HelloResponseMessage xmlns="Microsoft.WCF.Documentation">
'          <ResponseToGreeting xmlns="http://www.examples.com">Service received: Hello.</ResponseToGreeting>
'      </s:Body>    
'    </s:Envelope>
'    
  End Class

Keterangan

Untuk informasi selengkapnya, lihat bagian MessageHeaderAttribute Keterangan untuk detailnya.

Penting

Penting untuk diingat bahwa jika MustUnderstand properti berada true dalam pesan yang dikirim dan aplikasi di sisi penerimaan tidak memahami header yang dihasilkan kesalahan. Sebaliknya, jika header dengan mustUnderstand atribut header SOAP yang diatur ke true diterima oleh Windows Communication Foundation (WCF), itu harus menjadi bagian dari kontrak pesan (atau harus diproses oleh salah satu saluran Windows Communication Foundation (WCF); jika tidak, diasumsikan bahwa header tidak dipahami dan pengecualian dilemparkan.

Berlaku untuk