I have a client-server application, which intercommunicate via WCF. They also both use Castle Windsor for resolving dependencies.
My goal, is to completely avoid having to explicitly register server, or client WCF endpoints.
I have achieved the server-side by ‘convention’ using the following code
// 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
)
);
This code will find all classes in the current assembly, and any which implement a service-contract interface (identified by the ServiceContract attribute) will be registered (with UDP discovery) at the address “net.tcp://localhost:7601/[service-contract-interface-name]”.
Now, I just want the client-side of the equation.
Typically, to use castle to generate client-proxies for WCF contracts, the following code will work:
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),
);
What I want, is for Castle to do this kind of registration for all ‘service-contract’ interfaces in a given assembly – however the AllTypes helper seems to return only classes, not interfaces (which I guess makes it an ‘AllClasses’, not ‘AllTypes’!)… Can Castle do this, and what is the syntax? Krzysztof? (help!)
Thanks!
Apologies for such a late reply – a developer’s life is never a quiet one!
I dug out the code, and its not as ‘succinct’ as I would have liked, perhaps someone can look at integrating something like this in to Castle… but here goes…