Creating help for configuring a web service - ASP.NET?

We inherited some code that uses a third-party web service on an external server. Currently, all links are executed directly in the project and, thus, compiled to this place, etc. This problem is that there is a test and production server with different URLs for the web service.

Is there a simple way to make the link on the Internet more dynamic so that it can be defined in the web.config file and not require changing the actual source and recompiling to switch between servers?

+3
source share
1 answer

You can put the url in the appSettingsfile section web.config:

<appSettings>
    <add key="wsUrl" value="http://example.com/staging.asmx" />
</appSettings>

Then read the value in the constructor of the webservice proxy class and set the Url property to it :

public SomeProxy()
{
    Url = ConfigurationManager.AppSettings["wsUrl"];
}
+4
source

Source: https://habr.com/ru/post/1730084/


All Articles