title: Castle Windsor WCF interceptors
body: <p>I am having a hard time getting interceptors to work in a MVC application that is hosting WCF services. </p>
  
  <p>I want to add fine grained control over AOP using classes/methods decorated with attributes, but the interceptor is never called using the WCF facility.</p>
  
  <p>In <code>Global.asax</code> I have:</p>
  
  <pre><code>container = new WindsorContainer();
  container.AddFacility&lt;WcfFacility&gt;();
  container.Kernel.ComponentModelBuilder.AddContributor(new RequireAspects());
  container.Install(FromAssembly.This());
  </code></pre>
  
  <p><code>RequireAspects</code> wires up the interceptors:</p>
  
  <pre><code>public class RequireAspects : IContributeComponentModelConstruction
  {
      if (Attribute.IsDefined(model.Implementation, typeof(CacheAttribute)))
      {
          model.Interceptors.Add(InterceptorReference.ForType(typeof(Caching)));
      }
  }
  </code></pre>
  
  <p>Interceptor looks like so:</p>
  
  <pre><code>public class CacheAttribute : Attribute { };
  
  public class Caching : IInterceptor
  {
   ...
  }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>[Cache]
  public class TestService : ITestService
  {
      ...
  }
  </code></pre>
  
  <p>And finally services are installed:</p>
  
  <pre><code>public class ServicesInstaller : IWindsorInstaller
  {
      public void Install(Castle.Windsor.IWindsorContainer container, 
      Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
      {
          container.Register(AllTypes.FromThisAssembly()
                 .InNamespace("Test.Services")
                 .Configure((c =&gt; c.LifestyleTransient())));
      }
  }
  </code></pre>
  
  <p>Services configuration:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
    &lt;services&gt;
      &lt;service name="Test.Services.TestService"&gt;
        &lt;endpoint address=""
                  binding="webHttpBinding" 
                  contract="Test.Services.ITestService" /&gt;
      &lt;/service&gt;
    &lt;/services&gt;
    &lt;behaviors&gt;
      &lt;endpointBehaviors&gt;
        &lt;behavior name=""&gt;
          &lt;enableWebScript /&gt;
        &lt;/behavior&gt;
      &lt;/endpointBehaviors&gt;
      &lt;serviceBehaviors&gt;
         &lt;behavior name=""&gt;
           &lt;serviceMetadata httpGetEnabled="true" /&gt;
           &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
         &lt;/behavior&gt;
      &lt;/serviceBehaviors&gt;
    &lt;/behaviors&gt;
    &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                               multipleSiteBindingsEnabled="true" /&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>The interceptor is clearly added and a proxy is created, but the interceptor is never called.  </p>
  
  <p>I have reviewed this working example of interceptors with WCF, but doesn't meet my use case.<br>
  <a href="https://github.com/RussellPolitzky/Castle-Windsor-WCF-Service-With-Interceptor-and-Meta-Data-Publishing" rel="nofollow">https://github.com/RussellPolitzky/Castle-Windsor-WCF-Service-With-Interceptor-and-Meta-Data-Publishing</a></p>
  
  <p>The code above works for all other cases in which I use AOP in MVC and libraries.</p>