我有一个客户端 - 服务器应用程序,它通过WCF进行相互通信。他们也都使用Castle Windsor来解决依赖关系。Castle Windsor WCF基于约定的客户端服务注册
我的目标是完全避免必须显式注册服务器或客户端WCF端点。 我已经通过“公约”所取得的服务器端使用下面的代码
// registers all services which implement exactly 1 [ServiceContract]
_windsorContainer.Register(
AllTypes.FromThisAssembly().IncludeNonPublicTypes().Where(
t => 1 == (from i in t.GetInterfaces() where i.IsDefined(typeof(ServiceContractAttribute), true) select i).Count())
.Configure(c => c.LifeStyle.PerWcfSession()
.ActAs(new DefaultServiceModel().AddEndpoints(
WcfEndpoint.BoundTo(new NetTcpBinding())
.At("net.tcp://" + LocalAddress.ToString() + ":7601/" + c.ServiceType.Name),
WcfEndpoint.FromEndpoint(new UdpDiscoveryEndpoint())
))
).WithService.Select(
(Type type, Type[] baseTypes) => from i in type.GetInterfaces() where i.IsDefined(typeof(ServiceContractAttribute), true) select i
)
);
该代码会发现在当前装配的所有类,以及任何其实现服务合同接口(由ServiceContract类型标识)将在地址“net.tcp:// localhost:7601/[service-contract-interface-name]”上注册(通过UDP发现)。
现在,我只想要方程的客户端。
通常情况下,使用城堡生成客户代理的WCF的合同,下面的代码将工作:
var model = new DefaultClientModel
{
Endpoint = WcfEndpoint.ForContract<IServiceContract>().BoundTo(new NetTcpBinding()).Discover(typeof(IServiceContract))
};
container.Register(
Component.For<ChannelReconnectPolicy>(),
Castle.Facilities.WcfIntegration.WcfClient.ForChannels(model),
);
我想,是城堡,为所有“服务合同做这种登记'在给定的程序集中的接口 - 但AllTypes助手似乎只返回类,而不是接口(我猜它使它成为'AllClasses',而不是'AllTypes'!)... Castle可以做到这一点,语法是什么?克日什托夫? (帮助!)
谢谢!
你解决了这个问题吗?我想知道完全一样的东西......好问题! +1 – Eduard 2011-09-01 09:03:03