You need to set the URL of the web service at runtime.
In the code-behind class for your page, set the URL property of the proxy class to the required URL after instantiating the proxy object, as shown here:
Better still, by storing the URL in web.config and setting the URL property of the proxy class at runtime from the web.config setting, you can avoid changing the code whenever the URL changes.
The ability to configure an application without having to recompile its code every time you make a change in the location of its resources can be a time-saver. Since the URL for a web service can change, code your application to set the URL at runtime.
Whenever you add a web reference to a project, Visual Studio 2005 adds an entry to the <appSettings> section of the web.config containing the URL of the web reference, as shown here for the two web references added for the recipes in this chapter:
By using the URL in web.config and setting the URL property of the web service at runtime, no code changes are required when the URL changes: