在Castle Windsor注册wcf服务

时间:2012-05-01 11:51:37

标签: wcf castle-windsor wcffacility windsor-facilities

我有一个非常简单的服务,在不使用Castle时可以正常工作(这表明其他代码是正确的)。 我将我的svc文件更改为以下内容:

<%@ ServiceHost Service="Reporting.WebService.ReportingWebService" Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration"  %>

使用xml注册服务,如下所示:

  <component id="Reporting.WebService.ReportingWebService"
           service="Reporting.WebService.IReportingWebService, Reporting.WebService"
           type="Reporting.WebService.ReportingWebService, Reporting.WebService">
</component>

但是我收到以下错误:

[InvalidOperationException: Could not find a component with name Reporting.WebService.ReportingWebService, did you forget to register it?]   Castle.Facilities.WcfIntegration.WindsorServiceHostFactory`1.CreateServiceHost(String constructorString, Uri[] baseAddresses)
....

知道为什么没有注册? ?

----更新----

我在windsor配置中有这个:

<facilities>
    <facility id='wcf'
          type='Castle.Facilities.WcfIntegration.WcfFacility,
                Castle.Facilities.WcfIntegration' />
</facilities>

和ReportingWebService在另一个程序集中得到了证实。

1 个答案:

答案 0 :(得分:2)

我看不出电线有什么问题导致我认为无法找到你的组件或者可能没有加载类型。因为您的Web服务在另一个程序集中引用,请确保在Web项目中引用它。或者切换到在代码中使用Global.asax进行连接,这将强制您引用程序集并加载类型:

var container = new WindsorContainer();
container.AddFacility<WcfFacility>()
         .Register(Component.For<IReportingWebService>().ImplementedBy<ReportingWebService>());

//Additional wire up

//If you are using Windsor 3.0 and above then the following is not needed
DefaultServiceHostFactory.RegisterContainer(container.Kernel);
相关问题