我有一個客戶端 - 服務器應用程序,它通過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