Specify IP address of WCF endpoint at runtime
        Posted  
        
            by Mikey Cee
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Mikey Cee
        
        
        
        Published on 2010-03-23T08:14:27Z
        Indexed on 
            2010/03/23
            8:23 UTC
        
        
        Read the original article
        Hit count: 501
        
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
© Stack Overflow or respective owner