Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Consume C# WS in C# App
Message
From
16/03/2008 12:31:09
 
 
To
16/03/2008 11:07:04
General information
Forum:
ASP.NET
Category:
Web Services
Miscellaneous
Thread ID:
01302443
Message ID:
01302484
Views:
8
>Kevin,
>
>You can access the web reference directly, as in Viv's example, but we use a Web Service factory class for one simple reason:
>
>When you add a web reference to your project, the actual URL to that reference gets stored. At runtime, you may have a need to change that to something else (something you may have stored in a config file perhaps). When you instantiate the Web Service via a factory class, you can set the URL at runtime.
>
>
>public class WebServiceFactory
>{
>	// the default URL
>	private static string m_url = "http://localhost/webservices.myapp/";
>
>	public static SoapHttpClientProtocol GetWebService(SoapHttpClientProtocol ws)
>	{
>		string url    = ws.Url.ToLower();
>		string newurl = this.MyMethodToGetURLFromConfig();
>		if (newurl.Length == 0 || newurl.ToLower().Trim() == m_url)
>		{
>			return ws;
>		}
>		else
>		{
>			ws.Url = url.Replace(m_url, newurl);
>			return ws;
>		}
>	}
>
>
>And you use it like this:
>
>
>// declaration
>private MyApp.PersonnelWS.Personnel oWS;
>
>// instantiation
>this.oWS  = (MyApp.PersonnelWS.Personnel)WebServiceFactory.GetWebService(new MyApp.PersonnelWS.Personnel());
>
>// use as any other class method call
>string XML = this.oWS.GetPersonnel(MyKey);
>
Hi Bonnie,

The default URL is stored in the applicationsettings of the relevant config file and loaded from there anyway. Why not just change that entry directly?
Regards,
Viv
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform