0

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)

Tristan Djahel
  • 1,082
  • 2
  • 12
  • 22

1 Answers1

1

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();
Nissim
  • 6,395
  • 5
  • 49
  • 74