I have a bunch of remote machines all running the same WCF service over HTTP. I have a central configuration utility that needs to decide at runtime which of these to connect to. I do not want to define all the endpoints in the configuration file because this is all database driven.
I naively tried this:
CustomerServiceClient GetClientForIPAddress(string ipAddress)
{
string address = String.Format("http://{0}/customerservice.svc", ipAddress);
var client = new CustomerServiceClient("?", address);
return client;
}
where CustomerServiceClient is my service reference proxy class, but (unsurprisingly) it gave me the following error:
Could not find endpoint element with name '?' and contract 'SkyWalkerCustomerService.ICustomerService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
So how do I declare an endpoint at runtime and point my service reference to it?
.NET 3.5