我还没有找到其他人遇到这个问题,所以我假设发生这种情况是我自己的错。当谈到 WCF 和 Castle Windsor IoC 容器时,我非常绿色,所以这可能是发生这种情况的第一个原因。无论如何,我已经为此苦苦挣扎了几天,还没有找到原因。
首先,我使用 Castle Windsor 注册了我的服务。
var baseUri = new Uri("http://localhost:49246");
_container = new WindsorContainer();
var returnFaults = new ServiceDebugBehavior
{
IncludeExceptionDetailInFaults = true,
HttpHelpPageEnabled = true
};
var metadata = new ServiceMetadataBehavior { HttpGetEnabled = true };
_container.Register(
Component.For<IServiceBehavior>().Instance(returnFaults),
Component.For<IServiceBehavior>().Instance(metadata));
var baseUri = new Uri("http://localhost:49246");
_container = new WindsorContainer();
var returnFaults = new ServiceDebugBehavior
{
IncludeExceptionDetailInFaults = true,
HttpHelpPageEnabled = true
};
var metadata = new ServiceMetadataBehavior { HttpGetEnabled = true };
_container.Register(
Component.For<IServiceBehavior>().Instance(returnFaults),
Component.For<IServiceBehavior>().Instance(metadata));
_container
.Register(
Component
.For<IAccountDataAccessor>()
.ImplementedBy<AccountDataAccessor>(),
Component
.For<IInstitutionDataAccessor>()
.ImplementedBy<InstitutionDataAccessor>(),
Component
.For<IRelationshipDataAccessor>()
.ImplementedBy<RelationshipDataAccessor>(),
Component
.For<ITransactionDataAccessor>()
.ImplementedBy<TransactionDataAccessor>()
);
_container.AddFacility<WcfFacility>(f => { f.CloseTimeout = TimeSpan.Zero; });
_container.Register(
Component
.For<IAccountDataService>()
.ImplementedBy<AccountDataService>()
.Named("AccountDataService")
.LifeStyle.Is(Castle.Core.LifestyleType.Singleton)
.AsWcfService(new DefaultServiceModel()
.AddBaseAddresses(baseUri)
.AddEndpoints(WcfEndpoint
.ForContract(typeof(IAccountDataService))
.BoundTo(new WSHttpBinding()))),
Component
.For<IInstitutionDataService>()
.ImplementedBy<InstitutionDataService>()
.Named("InstitutionDataService")
.LifeStyle.Is(Castle.Core.LifestyleType.Singleton)
.AsWcfService(new DefaultServiceModel()
.AddBaseAddresses(baseUri)
.AddEndpoints(WcfEndpoint
.ForContract(typeof(IInstitutionDataService))
.BoundTo(new WSHttpBinding()))),
Component
.For<IRelationshipDataService>()
.ImplementedBy<RelationshipDataService>()
.Named("RelationshipDataService")
.LifeStyle.Is(Castle.Core.LifestyleType.Singleton)
.AsWcfService(new DefaultServiceModel()
.AddBaseAddresses(baseUri)
.AddEndpoints(WcfEndpoint
.ForContract(typeof(IRelationshipDataService))
.BoundTo(new WSHttpBinding()))),
Component
.For<ITransactionDataService>()
.ImplementedBy<TransactionDataService>()
.Named("TransactionDataService")
.LifeStyle.Is(Castle.Core.LifestyleType.Singleton)
.AsWcfService(new DefaultServiceModel()
.AddBaseAddresses(baseUri)
.AddEndpoints(WcfEndpoint
.ForContract(typeof(ITransactionDataService))
.BoundTo(new WSHttpBinding()))));
现在,当我尝试获取 AccountDataService 的服务参考时,它工作正常,没有错误。但是,当我尝试添加对机构数据服务的服务引用时,它会抛出一个异常:
Could not find a component with name InstitutionDataService, did you forget to register it?
这非常令人沮丧,我似乎无法在 Castle Windsor 文档中找到一个直接的答案(或缺少答案)。我试图实施这个 SO 问题中建议的解决方案:
但这也没有用。似乎没有任何组件已注册。另外,如果有帮助,这是我的 svc 标记:
<%@ ServiceHost Language="C#" Debug="true" Service="AccountDataService"
Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration" %>
所有服务都是一样的。
所以,我的问题是,为什么我的组件没有与 AccountDataService 一起注册?