MessageHeaderAttribute.MustUnderstand Propriedade
Definição
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
Valor da propriedade
true se o nó atuando na função Actor deve entender esse cabeçalho; caso contrário, false.true if the node acting in the Actor role must understand this header; otherwise, false.
Exemplos
O exemplo de código a seguir mostra o uso do MessageHeaderAttribute para criar um cabeçalho SOAP para a mensagem de resposta com as Name Namespace MustUnderstand Propriedades e definidas como valores apropriados para esse cabeçalho.The following code example shows the use of the MessageHeaderAttribute to create a SOAP header for the response message with the Name, Namespace and MustUnderstand properties set to values appropriate for this header. O exemplo de código é seguido por um exemplo da mensagem quando enviado.The code example is followed by an example of the message when sent.
[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
Comentários
Para obter mais informações, consulte a seção comentários de MessageHeaderAttribute para obter detalhes.For more information, see the Remarks section of MessageHeaderAttribute for details.
Importante
É importante lembrar que, se a MustUnderstand propriedade estiver true em uma mensagem sendo enviada e o aplicativo no lado de recebimento não entender o cabeçalho, uma falha será gerada.It is important to remember that if the MustUnderstand property is true in a message being sent and the application on the receiving side does not understand the header a fault is generated. Por outro lado, se um cabeçalho com o mustUnderstand atributo de cabeçalho SOAP definido como true é recebido por Windows Communication Foundation (WCF), ele deve ser parte do contrato de mensagem (ou deve ser processado por um dos canais de Windows Communication Foundation (WCF)); caso contrário, supõe-se que o cabeçalho não seja compreendido e uma exceção seja lançada.Conversely, if a header with the mustUnderstand SOAP header attribute set to true is received by Windows Communication Foundation (WCF), it must be a part of the message contract (or must be processed by one of the Windows Communication Foundation (WCF) channels); otherwise, it is assumed that the header is not understood and an exception is thrown.