根据配置更新服务参考地址?

| 在调试过程中,我添加了一些服务引用,这些引用指向调试计算机上的服务。有什么方法可以根据配置自动重新生成服务引用吗?我真的宁愿不必在准备发布时将它们全部指向Release服务器,然后在我需要调试时返回并再次更改它们,等等。 基本上,我需要以下内容(自动完成): 调试-> http://localhost/App/Service1.svc 发行-> http://myserver/Service1.svc     
已邀请:
无法对配置进行条件编译。我在某些项目中使用的一件事是在代码中包含#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执行任意命令,因此您可以根据构建配置使用自定义目标,然后运行一些命令来基于此更新配置文件。     
您可以使用web.config转换来解决此问题,而无需代码。 http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx     

要回复问题请先登录注册