Dynamic Web Service URLs

Usually when developing, there are several environments where your builds will be deployed on. For example: an environment for development, a uat environment for testing and acceptance from the users and the production environment for the final build.

When you use a web service, which is also deployed on different environments, it’s quite annoying to always rebuild your solution just so it’s compatible with a specific environment.

By using a configuration file and adding the web service url to the configuration file, you’ll be able to change the url in the configuration file without the need to rebuild the whole solution. This simplifies the deployment on multiple environments a lot.

You’ll have to create a class which extends your web service. This class will be instantiated with the url out of the configuration file.
Now you can have your solution deployed on different environments and you only have to change the url in the configuration file.

Webservice Class

public class WebService_Wrapper : Webservice_WS.Service
    public WebService_Wrapper (String Url) : base()
       this.Url = Url;

Initializing the web service

String url = ConfigurationManager.AppSettings["WebServiceUrl"];
Webservice_Wrapper ws = new Webservice_Wrapper(url);


Comments are closed.

%d bloggers like this: