Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Consume C# WS in C# App
Message
Information générale
Forum:
ASP.NET
Catégorie:
Web Services
Divers
Thread ID:
01302443
Message ID:
01302501
Vues:
8
Viv,

The code that Bonnie posted below looks like it's not creating a reference to the WS, but only
changing the URL on the WS if it's different than what's in the config file.

If so, what's the difference between storing it in the config file or coding it in the line:
private static string m_url = "http://localhost/webservices.myapp/";
Also, I don't understand this at all:
// What is MyApp a reference to? What is PersonnelWS? And the .Personnel is a class in the WS?
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);
>>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
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform