本文介绍了使用IParameterInspector.BeforeCall(字符串operationName,对象[]输入)中止通话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我实行IParameterInspector,以便能够使用BeforeCall和AfterCall一个自定义行为。 。我目前使用这些方法来进行一些验证调用我的WCF服务执行之前

I have a custom behavior in which I implement "IParameterInspector" to be able to use BeforeCall and AfterCall. I'm currently using these methods to make some verifications before the call execute on my WCF service.

下面是我的属性:

[AttributeUsage(AttributeTargets.Class)]
public class SendReceiveBehaviorAttribute : Attribute, IServiceBehavior
{
    public SendReceiveBehaviorAttribute()
    {
    }

    public void ApplyDispatchBehavior(ServiceDescription desc, ServiceHostBase host)
    {
        foreach (ChannelDispatcher cDispatcher in host.ChannelDispatchers)
        {
            foreach (EndpointDispatcher eDispatcher in cDispatcher.Endpoints)
            {
                foreach (DispatchOperation op in eDispatcher.DispatchRuntime.Operations)
                {
                    op.ParameterInspectors.Add(MyInspector);
                }
            }
        }
    }

    public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
    {
    }

    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
    }
}

和我的检查:

internal class MyInspector: IParameterInspector
{
    public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
    {
    }

    public object BeforeCall(string operationName, object[] inputs)
    {
        // Make some verifications and cancel if it fails.

        return null;
    }
}



编辑
什么是最好的办法?如果我的验证失败中止我的电话

EDITWhat would be the best way to abort my call if my verification fails?

推荐答案

抛出的异常是唯一的出路 - 据我所知 - 中止

Throwing exception is the only way - as far as I am aware - to abort.

这篇关于使用IParameterInspector.BeforeCall(字符串operationName,对象[]输入)中止通话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 07:32