MessageHeaderAttribute.MustUnderstand 属性    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定在 Actor 角色中起作用的节点是否必须理解此标头。 这将映射到 mustUnderstand SOAP 标头属性。
public:
 property bool MustUnderstand { bool get(); void set(bool value); };public bool MustUnderstand { get; set; }member this.MustUnderstand : bool with get, setPublic Property MustUnderstand As Boolean属性值
如果在 Actor 角色中起作用的节点必须理解此标头,则为 true;否则为 false。
示例
下面的代码示例演示如何使用 MessageHeaderAttribute 创建响应消息的 SOAP 标头,其中 Name、Namespace 和 MustUnderstand 属性设置为适合于此标头的值。 此代码示例之后的示例为发送时的消息示例。
 [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
注解
有关更多信息,请参见 MessageHeaderAttribute 的“备注”部分。
重要
请记住,如果要发送的消息的 MustUnderstand 属性为 true,而接收端上的应用程序不理解标头,则将生成错误,这一点很重要。 相反,如果将 SOAP 标头属性设置为的标头mustUnderstand由 true Windows Communication Foundation (WCF) 接收,则它必须是消息协定的一部分 (,或者必须由Windows Communication Foundation (WCF) 通道) 进行处理;否则,假定标头无法理解,并且引发异常。