dynamically connect to webservice

  • Thread starter Thread starter Ed S
  • Start date Start date
E

Ed S

Hi All,

We're upgrading our web project - currently we have a web app and a web
service - both written in C#. The web app communicates with the web
service for login authentication, the list of who's logged in, messaging
between logged in users, etc. For this first pass, we hardcoded the
location of the web service to localhost/MyWebService. Now, we want to
allow more than one web app, but still have only one web service.
Obviously we can't have the hardcoded localhost/MyWebService anymore. I
was thinking of storing the URL of the webservice in the registry of
each IIS machine that has the web app installed. Now the hard part -
how do I dynamically get the web app to comminicate with a web service
that I don't know its URL at compile time? Any help / nudges in the
right direction are greatly appreciated.

Thanks in advance,

--Ed
 
You can set the URL to the webservice dynamically at runtime from a setting
held somewhere like web.config

service = new thingService();
service.Timeout = 10000;
service.Url = ConfigurationSettings.AppSettings["WebServiceUrl"];

If your using VS.NET then choose the properties of the web service and
change the "Url Behavior" from "Static" to "Dynamic". This creates an entry
in the <appSettings> section of the Web.Config file that contains the Url
string.
--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
 
Back
Top