我有一个设置为托管在统一容器中的 WCF 服务。我打算使用这个容器来执行方法拦截。问题是我无法让我的拦截器开火......
首先在这里定义我的拦截器属性和处理程序:
[AttributeUsage(AttributeTargets.Method)]
public class PCSecurityAttribute : HandlerAttribute
{
public PCSecurityAttribute(Modules module, int modulePermission)
{
SecurityModule = module;
SecurityModulePermission = modulePermission;
}
public Modules SecurityModule
{
get;
set;
}
public int SecurityModulePermission
{
get;
set;
}
public override ICallHandler CreateHandler(IUnityContainer container)
{
return new PCSecurityCallHandler(0, SecurityModule,
SecurityModulePermission);
}
}
using System.ServiceModel.Security;
using MHC.PracticeConnect.Contract.Data.Security;
using Microsoft.Practices.Unity.InterceptionExtension;
namespace MHC.PracticeConnect.Service
{
public class PCSecurityCallHandler : ICallHandler
{
private Modules securityModule;
private int securityModulePermission;
public PCSecurityCallHandler(Modules module, int modulePermission)
{
securityModule = module;
securityModulePermission = modulePermission;
Order = 0;
}
public PCSecurityCallHandler(int order, Modules module,
int modulePermission)
{
securityModule = module;
securityModulePermission = modulePermission;
Order = order;
}
public IMethodReturn Invoke(IMethodInvocation input,
GetNextHandlerDelegate getNext)
{
bool validPermission = false;
// check security permission
IMethodReturn result;
if (validPermission)
result = getNext().Invoke(input, getNext);
else
throw new SecurityAccessDeniedException(
"The current user does not have security " +
"permissions to call this module.");
return result;
}
public int Order
{
get;
set;
}
}
}
在我的主机中,我尝试将其配置为使用拦截无济于事......帮助!!!!
public class DocumentTemplateServiceHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType,
Uri[] baseAddresses)
{
UnityServiceHost host =
new UnityServiceHost(serviceType, baseAddresses);
UnityContainer unity = new UnityContainer();
host.Container = unity;
host.Container.AddNewExtension<Interception>(); ;
host.Container.RegisterType<IDocumentTemplateService,
DocumentTemplateService>().Configure<Interception>().
SetInterceptorFor<IDocumentTemplateService>(
new TransparentProxyInterceptor());
return host;
}
}
我在这里做错了什么?