ReceiveActivity.OperationValidation 事件

定义

在接收到操作的消息并且需要验证时发生。

public:
 event EventHandler<System::Workflow::Activities::OperationValidationEventArgs ^> ^ OperationValidation;
[System.ServiceModel.SRCategory("Handlers")]
public event EventHandler<System.Workflow.Activities.OperationValidationEventArgs> OperationValidation;
[<System.ServiceModel.SRCategory("Handlers")>]
member this.OperationValidation : EventHandler<System.Workflow.Activities.OperationValidationEventArgs> 
Public Custom Event OperationValidation As EventHandler(Of OperationValidationEventArgs) 

事件类型

EventHandler<OperationValidationEventArgs>
属性
System.ServiceModel.SRCategoryAttribute

示例

下面的示例演示如何使用 OperationValidation 事件。

[System.Diagnostics.DebuggerNonUserCode]
private void InitializeComponent()
{
    ReceiveActivity receiveActivity1 = new ReceiveActivity();
    receiveActivity1.OperationValidation += new EventHandler<OperationValidationEventArgs>(receiveActivity1_OperationValidation);
}

void receiveActivity1_OperationValidation(object sender, OperationValidationEventArgs e)
{
    OperationContext context = OperationContext.Current;
    bool authorized = false;
    foreach (ClaimSet claims in context.ServiceSecurityContext.AuthorizationContext.ClaimSets)
    {
        if (claims.ContainsClaim(AuthorizedClaim))
        {
            authorized = true;
        }
    }
    e.IsValid = authorized;
}

注解

这是一个可选的事件处理程序,它在 ReceiveActivity 活动即将收到消息时激发。 可以使用关联的处理程序来执行基于 ClaimSet 的安全检查,以对由 ReceiveActivity 活动实现的服务操作的客户端调用进行授权。

在事件处理程序中将 OperationValidationEventArgs.IsValid 设置为 false 会拒绝服务操作调用,并且客户会收到 FaultException。 如果将 OperationValidationEventArgs.IsValid 设置为 true,则服务操作调用将成功完成,并且 ReceiveActivity 活动将接收并处理消息。

适用于