0

我正在尝试在我的 web.config 文件中定义一个服务端点,以便我可以将我们的暂存构建指向一个暂存 Web 服务和一个不同的生产端点。这里有一个问题涉及 Visual Studio 2005/2008 中的Web 引用。我正在添加一个服务引用,但似乎在属性中找不到任何可以让我将 Url 行为定义为动态的东西。

我想在 appSettings 中定义 url。有谁知道这在 Visual Studio 2010 for Service References 中是如何工作的?

4

2 回答 2

1

You can change the end point using what is known as a config transformation.

In short, a config transformation allows you to tweak various config settings depending on your deployment. This is a technique commonly used for changing connection strings as well.

Here's more reading: How to: Transform Web.config When Deploying a Web Application Project

于 2012-06-19T02:50:33.783 回答
0

您可以在创建 Web 服务之后但在使用它之前在运行时设置 URL:

string localUrl = "localhost";
string stagingUrl = "http://staging.example.com"
string url = Request.IsLocal ? localUrl : stagingUrl;

var _webService = new YourWebService { Url = url };
于 2012-06-19T02:35:05.103 回答