Murugan.com
Murugan Andezuthu Dharmaratnam

  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  



VB .NET Dynamically Add WebService to a desktop application

Home   VB.NET   VB .NET Dynamically Add WebService to a desktop application          


I have a desktop application which interacts with my websites. we use the same webservice 
in all the different websites. I would like to dynamically add a webservice to my application. 


Finally I was looking at the on-line help (RTFM), and I found a method of the class (SoapHttpClientProtocol) from which my web reference object was created that allowed me to set the "Url" that specified the location of the Web Service. At this point, I realized I could delete all but one of my web references, and then set the "Url" at run-time to choose the appropriate Web Service. I simply renamed my one remaining web reference (right click in the Solution Explorer) from "localhost" to a common name, like "AcmecoService". I then set the "AmcecoService" object's "Url" at run-time from a value stored in "appSettings" of the web.config file.

  service = new Acmeco.AcmecoService();
  service.Timeout = 10000;
  service.Url = ConfigurationSettings.AppSettings["AcmecoWebServiceUrl"];
   

This solution may be obvious to many, especially those that read (and retain) all of the .NET Web Service/Reference documentation. For me, it was a real simplification of a solution to an annoying problem.

Oopps...I found an even easier method to set the Web Service Url dynamically using Visual Studio properties.

And now I've found that the Visual Studio is way ahead of me. Simply choose the properties of the web service and change the "Url Behavior" from "Static" to "Dynamic". This will automatically create an entry in the  section of the Web.Config file that contains the Url string. The constructor of the Web Service proxy class is automatically changed to set the Url property to the value stored in Web.Config.







  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  

Copyright 2009 @ Murugan Andezuthu Dharmaratnam