Attilah
Attilah

Reputation: 17930

Unity does not intercept WCF Service calls

I have a WCF service and I want to intercept the method CreateOrder whenever it is called :

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

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

CreateOrderCallHandlerAttribute inherits from ICallHandler.

So, I have used the method described in this post : http://weblogs.asp.net/fabio/archive/2009/03/24/inversion-of-control-with-wcf-and-unity.aspx

I use the configuration file to configure dependency injection for types the service depends on. and as soon as the unity container returns after loading the config file, I add the following code to it :

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

but the intercepting code is still not called whenever the method is called. what am I missing ?

Upvotes: 2

Views: 768

Answers (1)

ErnieL
ErnieL

Reputation: 5801

Set the interceptor on the implementation instead of the interface being mapped. Try:

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

Upvotes: 1

Related Questions