Setting URL of web service at runtime

  • Thread starter Thread starter Tim Johnson
  • Start date Start date
T

Tim Johnson

I'd like to be able to set the URL in my web-service client at runtime. I
see that when you instantiate a new one you can then set the URL:

MyWS.myservice1 ws = new MyWS().myservice1
ws.URL=<newurl>

But is there a way to set it once like a static for the life of the app?
Otherwise I have to set that URL in all the dozens of places I want to use
it throughout my app. And I don't want to compile it in since I need to
swap between 2 URLs during development. Any suggestions?

--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
 
You can create a Globals class in your application that holds cached
references to
your two web services (each one pointed at a distinct URL). You can do this
by making the Globals class a singleton, instantiate the web service
references
once and only once in the constructor of the Globals class, and accessing
your
web services from anywhere in your application via code like:

Globals.Instance.Service1.Method1();
Globals.Instance.Service2.Method1();

You'll need code in the Service accessors ("getters") to make sure the web
svc
reference is not null and if it is, reinitialize it before returning it.

Darren Shaffer
Principal Architect
Connected Innovation
 
Back
Top