如何使用Castle Windsor在客户端注册多个WCF服务
本文关键字:WCF 服务 注册 客户端 何使用 Castle Windsor | 更新日期: 2023-09-27 18:27:01
我正试图使用WCFFacility在我的WinForms客户端上向Castle Windsor注册我的WCF服务。我可以使用一次轻松地完成这一步
container.Register(Component.For<IMyService>()
.AsWcfClient(new DefaultClientModel
{
Endpoint = WcfEndpoint.BoundTo(new BasicHttpBinding { MaxReceivedMessageSize = 3000000 })
.At("http://localhost:51324/MyService.svc")
}));
然而,我有数百人试图遵循这个答案
我用了这个代码:
container.Register(
Types
.FromAssemblyContaining<IMyService>()
.Pick()
.If(s => s.Name.EndsWith("Service"))
.Configure(
configurer => configurer.Named(configurer.Implementation.Name)
.AsWcfClient(new DefaultClientModel
{
Endpoint = WcfEndpoint.BoundTo(new BasicHttpBinding { MaxReceivedMessageSize = 3000000 })
.At(string.Format("http://localhost:{0}/{1}.svc", Port, configurer.Name.Substring(1)))
})));
不幸的是,在尝试解决我的服务时,会出现以下错误:"类型MyNamespace.IMyService是抽象的。因此,不可能将其实例化为服务‘IMyService’的实现。你忘了代理它了吗?"
修复了它!
Container.Kernel.AddFacility<WcfFacility>();
据推测,注册刚刚失败,导致Windsor将接口注册为实现类。