Unity不拦截WCF服务调用

时间:2011-11-01 15:54:15

标签: c# .net wcf unity-container aop

我有一个WCF服务,我想在调用时拦截CreateOrder方法:

[ServiceContract]
public interface IOrderService
{
    [OperationContract]
    [CreateOrderCallHandlerAttribute]
    void CreateOrder(string orderXML);
}

public class OrderService : IOrderService
{
    public void CreateOrder(string orderXML)
    {
        // ...
    }    
}

CreateOrderCallHandlerAttribute继承自ICallHandler。

所以,我使用了这篇文章中描述的方法:http://weblogs.asp.net/fabio/archive/2009/03/24/inversion-of-control-with-wcf-and-unity.aspx

我使用配置文件为服务所依赖的类型配置依赖注入。并且在加载配置文件后,只要Unity容器返回,我就会向它添加以下代码:

        UnityConfigurationSection configuration = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
        configuration.Containers.Default.Configure(Container);
        Container.AddNewExtension<Interception>();
        Container.Configure<Interception>().SetInterceptorFor<IOrderService>(new TransparentProxyInterceptor());

但是每当调用该方法时,仍然不会调用拦截代码。我错过了什么?

1 个答案:

答案 0 :(得分:1)

在实现上设置拦截器而不是映射的接口。尝试:

Container.Configure<Interception>().SetInterceptorFor<OrderService>(new TransparentProxyInterceptor());