2011-11-01 99 views
2

我有一个WCF服务,我想拦截方法CreateOrder时,它被称为:团结不拦截WCF服务调用

[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

我使用配置文件来配置的依赖注入类型的服务依赖。并尽快加载配置文件后,统一容器的回报,我下面的代码添加到它:

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

但每当该方法被称为拦截代码仍然不叫。我错过了什么?

回答

1

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

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