BeforeCall と AfterCall を使用できるように「IParameterInspector」を実装するカスタム動作があります。現在、これらのメソッドを使用して、WCF サービスで呼び出しを実行する前にいくつかの検証を行っています。
これが私の属性です:
[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;
}
}
編集 検証が失敗した場合に通話を中止する最良の方法は何ですか?