You could use relative addresses programmatically, but you still need to know the base address (or just use localhost:8080 as the base) - it's not possible to use relative addresses via the web.config
unless you build a custom configuration or leverage AppSettings
.
// create bindings & endpoints
var baseAddress = System.ConfigurationManager.AppSettings["baseAddress"];
var binding = new System.ServiceModel.BasicHttpBinding();
var endpoint = new EndpointAddress(baseAddress + "/ServiceX.svc");
You could also load the client endpoint address from the web.config
and override the base address using UriBuilder
for similar means.