CorvettePower.COM
13Apr/05

Creating Dymanic Web Service References in Visual Studio .NET 2003

Found the following samples that help you create a web service in a .NET project that is Dynamic. I got tired of having to create versions of my project every time we changed the web service URL. Especially as we moved from Dev, Test, Prod. The binaries were getting confusing.

Dynamically Change Webservice URL


  1. register a webservice ( I then changed the folder to the default name of the web service i wanted)
  2. right click the webservice change URL Behavior to Dynamic
  3. click the 'show all files' icon in solution explorer
  4. in the web reference edit the Reference.cs file
  5. change class constructor such that you add the parts in bold. Note some comments are in bold.)


public wsMLA(string urlSetting) {
// string urlSetting = System.Configuration.ConfigurationSettings.AppSettings["wsMLA-test.com.company.wsMLA"];
if ((urlSetting != null)) {
this.Url = string.Concat(urlSetting, "");
}
else {
this.Url = "http://wsMLA.company.com/wsMLA/wsMLA.asmx";
}
}

Then you can set the URL when you instantiate the class.

Thanks goes to the folks at dotnet.editme.com
http://dotnet.editme.com/tipDynamicallyChangeWebserviceURL

Trackbacks are disabled.