Reputation: 1941
In a WCF Web Services deployment I need an Web Service to connect to multiple services of the same type. Those services are dinamically added to the deployment, and their numbers should be flexible. Clearly, the usual approach "create the binding" is not a solution in this case, because I would need to create bindings to every service I may end up using.
What would be the recommended approach for this? At first I was thinking of creating a binding (before compile time) to one of the multiple services. New services added would just communicate their endpoint and before sending them something I would change the endpoint name of the services. Which seems quite wrong and bad if I want to send in parallel to those services.
Is there a proper way of dealing with services of the same type without duplicating bindings?
I'm not customed with more complex scenarios for WCF and if I didn't explained good this issue it could be great to be helped on rephrasing this question and finding out new search words for my issue.
Upvotes: 0
Views: 523
Reputation: 2577
I would suggest configuring the client programmatically, he is an example How to programmatically connect a client to a WCF service?. Endpoint URLs you can store in a saparate file. The file can be modified durin deployment
var myBinding = new BasicHttpBinding();
var urlList = GetUrlsFromCustomConfigFile();
var factoriesOfTheSameType = new List<ChannelFactory<IMyService>>();
foreach(var url in urlList)
{
var myEndpoint = new EndpointAddress(url);
var myChannelFactory = new ChannelFactory<IMyService>(myBinding, myEndpoint);
factoriesOfTheSameType.Add(myChannelFactory);
}
Now you can use 'myChannelFactory' to create clients and call them in parallel or do whatever you need with it.
Upvotes: 1