更改web服务端点的存储位置

时间:2022-03-21 16:50:53

I have a basic SOAP service that I generated from a provided WSDL. The WSDL specifies the connection endpoint, which is replicated in the Web Service as an entry in the Settings.settings file at the Application level, and consequently in an AppSettingsGroup in an app.config for the project.

我有一个基本的SOAP服务,是我从提供的WSDL生成的。WSDL指定连接端点,该端点作为设置中的一个条目在Web服务中复制。在应用程序级别上的设置文件,然后在项目的app.config中的AppSettingsGroup中。

The problem is twofold:

问题是双重的:

  1. This project (which isn't the primary project of the solution) has an app.config all its own, for this sole reason; otherwise there'd be only the main exe's config.

    由于这个原因,这个项目(不是解决方案的主要项目)有一个app.config本身。否则只有主exe的配置。

  2. The endpoint must change when building for the production environment. Currently I have to go in and change this setting separately from my main config changes (which I've set up with configSource locations that I can easily switch).

    在为生产环境构建时,端点必须更改。目前,我必须将这个设置与我的主要配置更改分开(我已经设置了我可以轻松切换的configSource位置)。

It would be ideal to move the endpoint setting from being an entry in the settings file to an appSetting in the main config layout. Then, when building for production, all I have to do is "flip a bit" in one location in the entire project and the app is now pointed at production environments. However, the reference in the web service is generated code. Is there a way to specify a custom location for this setting that won't be blown away if/when I refresh the service?

将端点设置从设置文件中的条目移动到主配置布局中的appset是非常理想的。然后,在构建产品时,我所要做的就是在整个项目的一个位置“翻转一点”,应用程序现在指向生产环境。但是,web服务中的引用是生成的代码。是否有一种方法可以为这个设置指定一个自定义位置,当我刷新服务时不会被吹走?

1 个解决方案

#1


1  

When instantiating the autogenerated proxy class in your code you could set the Url property:

在代码中实例化自动生成的代理类时,可以设置Url属性:

string url = ConfigurationManager.AppSettings["fooUrl"];
using (var client = new AutoGeneratedServiceClient { Url = url })
{
    client.SomeMethod();
}

and then you could store the url in your main configuration file.

然后可以将url存储在主配置文件中。

#1


1  

When instantiating the autogenerated proxy class in your code you could set the Url property:

在代码中实例化自动生成的代理类时,可以设置Url属性:

string url = ConfigurationManager.AppSettings["fooUrl"];
using (var client = new AutoGeneratedServiceClient { Url = url })
{
    client.SomeMethod();
}

and then you could store the url in your main configuration file.

然后可以将url存储在主配置文件中。