CallbackBehaviorAttribute.ValidateMustUnderstand Propriedade
Definição
Obtém ou define um valor que especifica se o sistema ou o aplicativo reforça o processamento de cabeçalho SOAP MustUnderstand.Gets or sets a value that specifies whether the system or the application enforces SOAP MustUnderstand header processing.
public:
property bool ValidateMustUnderstand { bool get(); void set(bool value); };
public bool ValidateMustUnderstand { get; set; }
member this.ValidateMustUnderstand : bool with get, set
Public Property ValidateMustUnderstand As Boolean
Valor da propriedade
true Se o sistema for executar o processamento de cabeçalho SOAP MustUnderstand ; caso contrário false , o que indica que o aplicativo executa esse processamento.true if the system is to perform SOAP header MustUnderstand processing; otherwise false, which indicates that the application performs this processing. O valor padrão é true.The default value is true.
Exemplos
O exemplo de código a seguir mostra um CallbackBehaviorAttribute em um objeto de retorno de chamada que usa o SynchronizationContext objeto para determinar a qual thread realizar marshaling, a ValidateMustUnderstand propriedade para impor a validação de mensagem e a IncludeExceptionDetailInFaults propriedade para retornar exceções como FaultException objetos para o serviço para fins de depuração.The following code example shows a CallbackBehaviorAttribute on a callback object that uses the SynchronizationContext object to determine which thread to marshal to, the ValidateMustUnderstand property to enforce message validation, and the IncludeExceptionDetailInFaults property to return exceptions as FaultException objects to the service for debugging purposes.
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading;
namespace Microsoft.WCF.Documentation
{
[CallbackBehaviorAttribute(
IncludeExceptionDetailInFaults= true,
UseSynchronizationContext=true,
ValidateMustUnderstand=true
)]
public class Client : SampleDuplexHelloCallback
{
AutoResetEvent waitHandle;
public Client()
{
waitHandle = new AutoResetEvent(false);
}
public void Run()
{
// Picks up configuration from the configuration file.
SampleDuplexHelloClient wcfClient
= new SampleDuplexHelloClient(new InstanceContext(this), "WSDualHttpBinding_SampleDuplexHello");
try
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Enter a greeting to send and press ENTER: ");
Console.Write(">>> ");
Console.ForegroundColor = ConsoleColor.Green;
string greeting = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Called service with: \r\n\t" + greeting);
wcfClient.Hello(greeting);
Console.WriteLine("Execution passes service call and moves to the WaitHandle.");
this.waitHandle.WaitOne();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Set was called.");
Console.Write("Press ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("ENTER");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write(" to exit...");
Console.ReadLine();
}
catch (TimeoutException timeProblem)
{
Console.WriteLine("The service operation timed out. " + timeProblem.Message);
Console.ReadLine();
}
catch (CommunicationException commProblem)
{
Console.WriteLine("There was a communication problem. " + commProblem.Message);
Console.ReadLine();
}
}
public static void Main()
{
Client client = new Client();
client.Run();
}
public void Reply(string response)
{
Console.WriteLine("Received output.");
Console.WriteLine("\r\n\t" + response);
this.waitHandle.Set();
}
}
}
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Threading
Namespace Microsoft.WCF.Documentation
<CallbackBehaviorAttribute(IncludeExceptionDetailInFaults:= True, UseSynchronizationContext:=True, ValidateMustUnderstand:=True)> _
Public Class Client
Implements SampleDuplexHelloCallback
Private waitHandle As AutoResetEvent
Public Sub New()
waitHandle = New AutoResetEvent(False)
End Sub
Public Sub Run()
' Picks up configuration from the configuration file.
Dim wcfClient As New SampleDuplexHelloClient(New InstanceContext(Me), "WSDualHttpBinding_SampleDuplexHello")
Try
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine("Enter a greeting to send and press ENTER: ")
Console.Write(">>> ")
Console.ForegroundColor = ConsoleColor.Green
Dim greeting As String = Console.ReadLine()
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine("Called service with: " & Constants.vbCrLf & Constants.vbTab & greeting)
wcfClient.Hello(greeting)
Console.WriteLine("Execution passes service call and moves to the WaitHandle.")
Me.waitHandle.WaitOne()
Console.ForegroundColor = ConsoleColor.Blue
Console.WriteLine("Set was called.")
Console.Write("Press ")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("ENTER")
Console.ForegroundColor = ConsoleColor.Blue
Console.Write(" to exit...")
Console.ReadLine()
Catch timeProblem As TimeoutException
Console.WriteLine("The service operation timed out. " & timeProblem.Message)
Console.ReadLine()
Catch commProblem As CommunicationException
Console.WriteLine("There was a communication problem. " & commProblem.Message)
Console.ReadLine()
End Try
End Sub
Public Shared Sub Main()
Dim client As New Client()
client.Run()
End Sub
Public Sub Reply(ByVal response As String) Implements SampleDuplexHelloCallback.Reply
Console.WriteLine("Received output.")
Console.WriteLine(Constants.vbCrLf & Constants.vbTab & response)
Me.waitHandle.Set()
End Sub
End Class
End Namespace
Comentários
Use a ValidateMustUnderstand propriedade para desativar a validação imposta de cabeçalhos de mensagens de chegada.Use the ValidateMustUnderstand property to turn off the enforced validation of arriving message headers. Na execução normal, os cabeçalhos de mensagem são comparados com a UnderstoodHeaders propriedade para confirmar se os cabeçalhos de chegada são manipulados explicitamente pelo tempo de execução do objeto de retorno de chamada.In normal execution, message headers are compared against the UnderstoodHeaders property to confirm that arriving headers are explicitly handled by the callback object runtime. Defina isso como false para desabilitar essa verificação.Set this to false to disable this checking. Quando definido como false , o aplicativo deve verificar os cabeçalhos marcados com MustUnderstand = "true" e retornar uma falha se um ou mais deles não foram compreendidos.When set to false, the application must check for headers marked with MustUnderstand="true" and return a fault if one or more of them were not understood. Isso é útil quando o retorno de chamada deve aceitar todas as mensagens SOAP de entrada (por exemplo, ao usar mensagens digitadas ou não tipadas) e executar o processamento de cabeçalho personalizado.This is useful when the callback is supposed to accept any incoming SOAP messages (for example, when using typed or untyped messages) and perform custom header processing.