MessageHeaderAttribute.MustUnderstand Свойство

Определение

Указывает, должен ли узел, выступающий в роли Actor, понимать этот заголовок. Сопоставляется с атрибутом заголовка SOAP mustUnderstand.

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

Значение свойства

Значение true, если узел, выступающий в роли Actor, должен понимать этот заголовок; в противном случае — значение 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 в отправляемом сообщении, а приложение на принимающей стороне не понимает заголовок, создается ошибка. И наоборот, если заголовок с mustUnderstand атрибутом заголовка SOAP, которому задано значение true , получается Windows Communication Foundation (WCF), он должен быть частью контракта сообщения (или должен обрабатываться одним из каналов Windows Communication Foundation (WCF) ); в противном случае предполагается, что заголовок не распознается и создается исключение.

Применяется к