Thanks to this and subsequenbtly this, I found what I was looking for.
IParameterInspector
does not need to be at the IOperationBehavior
level. They can be at the IServiceBehavior
level. In the service level ApplyDispatchBehavior
method you need to loop through all its operations and assign the inspector behaviour.
My class in full...
[AttributeUsage(AttributeTargets.Class)]
public class ServiceLevelParameterInspectorAttribute : Attribute, IParameterInspector, IServiceBehavior
{
public object BeforeCall(string operationName, object[] inputs)
{
// Inspect the parameters.
return null;
}
public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
{
}
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
{
if (channelDispatcher == null)
{
continue;
}
foreach(var endPoint in channelDispatcher.Endpoints)
{
if (endPoint == null)
{
continue;
}
foreach(var opertaion in endPoint.DispatchRuntime.Operations)
{
opertaion.ParameterInspectors.Add(this);
}
}
}
}
}