Refresh service reference address based on configuration?

During debugging, I added a bunch of service links that point to services on the Debug machine. Is there a way to automatically restore service links based on configuration? I really wouldn’t have to go through and point everything to the Release server when I’m ready to release, and then when I need to debug, go back and change them again, etc.

Basically, I want the following (done automatically):

+3
source share
2 answers

. , , , #if- , . - :

static void Main() {
    TestClient client = new TestClient();
    UpdateAddress(client.Endpoint);
}
static void UpdateAddress(ServiceEndpoint endpoint) {
    string address = endpoint.Address.Uri.ToString();
    int svcIndex = address.IndexOf(".svc");
    int serviceIndex = address.LastIndexOf("/", svcIndex);
    address = address.Substring(serviceIndex);
#if DEBUG
    address = "http://localhost/App" + address;
#else
    address = "http://myserver" + address;
#endif
    endpoint.Address = new EndpointAddress(address);
}

, , , , , msbuild. IIRC msbuild, , .

+3

All Articles