WCFサービスをホストするASP.NETMVC3アプリケーションを構築しました。実際の作業を行うサービスクラスは、クラスライブラリ内にあります。Windsor WCFファシリティを使用して、サービスリクエストに応じて配線しようとしています。
これが私のウィンザーコンテナファクトリーです:
public class WindsorContainerFactory
{
private static IWindsorContainer container;
private static readonly object sync = new Object();
public static IWindsorContainer Current()
{
if(container == null) {
lock (sync)
{
if (container == null)
{
container = new WindsorContainer();
container.Install(new ControllerInstaller());
container.Install(new NHibernateSessionInstaller());
container.Install(new RepositoryInstaller());
container.Install(new ServiceInstaller());
}
}
}
return container;
}
}
Global.asaxで、WindsorContainerFactory.Current()を1回呼び出して、ファクトリが構築されていることを保証します。
protected void Application_Start()
{
WindsorContainerFactory.Current();
ControllerBuilder.Current.SetControllerFactory(typeof(WindsorControllerFactory));
...
次のクラスでサービスをインストールします。
public class ServiceInstaller : IWindsorInstaller
{
public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
{
container.Kernel.AddFacility<WcfFacility>();
container.Kernel.Register(
Component
.For<ICustomerService>()
.ImplementedBy<CustomerService>()
.Named("CustomerService"));
}
}
次に、プロジェクトに新しいWCFサービスを追加し、コードビハインドファイルを削除して、svcマークアップを次のように変更しました。
<%@ ServiceHost Language="C#" Debug="true"
Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory,
Castle.Facilities.WcfIntegration" Service="CustomerService" %>
ご覧のとおり、ウィンザー内にインストールされている他のコンポーネント(リポジトリ、コントローラーなど)がありますが、これはうまく機能しているようです。
私の問題は、WCFクライアント(コンソールアプリ)が次のエラーを受け取ることです: HttpContext.Currentはnullです。PerWebRequestLifestyleはASP.Netでのみ使用できます
クライアントコード:
CustomerServiceClient c = new Services.Customers.CustomerServiceClient();
CustomerResponse resp = c.GetCustomerBySurname("Lolman");
c.Close();
誰かが私を正しい方向に向けることができますか?前もって感謝します!