开发者

Change storage location of a web service endpoint

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.

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 ex开发者_C百科e's config.

  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).

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?


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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜