2012-01-19 29 views
0

WCFサービスをホストしているMVCアプリケーションでインターセプタを動作させるのに苦労しています。Castle Windsor WCFインターセプタ

属性で装飾されたクラス/メソッドを使用してAOPをきめ細かく制御したいと思っていますが、WCF機能を使用してインターセプタが呼び出されることはありません。 Global.asax

私が持っている:

container = new WindsorContainer(); 
container.AddFacility<WcfFacility>(); 
container.Kernel.ComponentModelBuilder.AddContributor(new RequireAspects()); 
container.Install(FromAssembly.This()); 

RequireAspects配線アップインターセプタ:

public class RequireAspects : IContributeComponentModelConstruction 
{ 
    if (Attribute.IsDefined(model.Implementation, typeof(CacheAttribute))) 
    { 
     model.Interceptors.Add(InterceptorReference.ForType(typeof(Caching))); 
    } 
} 

インターセプタはそうのようになります。

public class CacheAttribute : Attribute { }; 

public class Caching : IInterceptor 
{ 
... 
} 

サービス:

[Cache] 
public class TestService : ITestService 
{ 
    ... 
} 

そして最後にサービスがインストールされています

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 => c.LifestyleTransient()))); 
    } 
} 

サービス構成:

<system.serviceModel> 
    <services> 
    <service name="Test.Services.TestService"> 
     <endpoint address="" 
       binding="webHttpBinding" 
       contract="Test.Services.ITestService" /> 
    </service> 
    </services> 
    <behaviors> 
    <endpointBehaviors> 
     <behavior name=""> 
     <enableWebScript /> 
     </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
     <behavior name=""> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
          multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 

インターセプターは明らかに追加され、プロキシが作成されますが、インターセプタが呼び出されることはありません。

WCFでこのインターセプタの動作例を見直しましたが、私のユースケースを満たしていません。
https://github.com/RussellPolitzky/Castle-Windsor-WCF-Service-With-Interceptor-and-Meta-Data-Publishing

上記のコードは、MVCとライブラリでAOPを使用する他のすべてのケースで機能します。

+0

.svcファイルまたはサービスをインスタンス化するコードを表示してください。 –

+0

申し訳ありません。それはDefault Factoryを使用しています。 <%@ ServiceHost Language = "C#" Debug = "true" Service = "Services.TestService" CodeBehind = "TestService.svc.cs" Factory = "Castle.Facilities.WcfIntegration.DefaultServiceHostFactory、Castle.Facilities.WcfIntegration"%> – SSmith

答えて

0

あなたのサービス方法(図示せず)はおそらく仮想として宣言されていません。インターセプタは、インターフェイスまたはクラスの仮想メンバーを解決するときにのみ機能します。

+0

Hmm。私はそれを試さなければならない。ファシリティが参照を解決する方法については不明です。あなたが見ることができるように、ITestServiceがありますが、それから解決されていない場合、それは確かな可能性です。私は朝にチェックします。 – SSmith

+0

デフォルトの動作は、コンポーネント名(Test.Services.TestService)を使用して解決することです。つまり、クラス(インターフェイスではない)が返されるため、「仮想」が必要です。 –

+0

それでした。ありがとう。 – SSmith

関連する問題