Reputation: 1212
My WCF client can connect to several endpoints. But they all have different addresses, bindings and contracts. So my question is : How can I create my WCF client programmatically depending just of the name of my endpoint I want to connect to (which I have in my code)
Upvotes: 0
Views: 1007
Reputation: 6553
If I understood your question correctly, I believe this is the answer [using IPC, can be easily converted to other communication types]
Listener:
_host = new ServiceHost(typeof(ContractClass));
_host.AddServiceEndpoint(typeof(IContract), new NetNamedPipeBinding(), new Uri("net.pipe://localhost/" + listenerEndpointName));
_host.Open();
Client:
var factory = new ChannelFactory<IContract>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/" + listenerEndpointName));
IContract proxy = factory.CreateChannel();
Upvotes: 1