如何在不重新编译的情况下在 .NET 中动态切换 Web 服务地址? [英] How can I dynamically switch web service addresses in .NET without a recompile?

查看:27
本文介绍了如何在不重新编译的情况下在 .NET 中动态切换 Web 服务地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有引用 Web 服务的代码,我希望该 Web 服务的地址是动态的(从数据库、配置文件等中读取),以便轻松更改.它的一个主要用途是部署到机器名称和 IP 地址不同的多个环境中.Web 服务签名在所有部署中都相同,只是位于其他地方.

I have code that references a web service, and I'd like the address of that web service to be dynamic (read from a database, config file, etc.) so that it is easily changed. One major use of this will be to deploy to multiple environments where machine names and IP addresses are different. The web service signature will be the same across all deployments, just located elsewhere.

也许我刚刚被 Visual Studio 的添加 Web 引用"向导宠坏了 - 不过这看起来应该是相对容易的.

Maybe I've just been spoiled by the Visual Studio "Add Web Reference" wizard - seems like this should be something relatively easy, though.

推荐答案

当您生成 Web 引用并在解决方案资源管理器中单击 Web 引用时.在属性窗格中,您应该会看到如下内容:

When you generate a web reference and click on the web reference in the Solution Explorer. In the properties pane you should see something like this:

将值更改为 dynamic 会在您的 app.config 中添加一个条目.

Changing the value to dynamic will put an entry in your app.config.

这是 CodePlex 文章,其中包含更多信息.

Here is the CodePlex article that has more information.

这篇关于如何在不重新编译的情况下在 .NET 中动态切换 Web 服务地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆