>I completely don't understand this. I get the idea of a factory, but I don't understand the code.
>
>First, I'm getting "The type or namespace name 'SoapHttpClientProtocol' could not be found (are you
>missing a using directive or an assembly reference?)"
>
>Aside from me asking what reference I'm missing, how do I find out that info the next time someone
>provides a code snippet?
Hi,
PMJI
To answer the second part first: Just look up the class in help - that will tell you both the namespace and the assembly you are looking for. So, for SoapHttpClientProtocol it is:
System.Web.Services.Protocols.SoapHttpClientProtocol in System.Web.Services.dll
HTH,
Viv
>
>
>>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);
>>
>>
>>~~Bonnie