Show SingleWS.cs syntax highlighted
using System;
using System.Net;
using Whiteboard.MaseWS;
namespace Whiteboard
{
/// <summary>
/// Summary description for SingleWS.
///
/// This class implements the webservices as a singleton.
/// This provides several advantages:
/// 1. keeps the number of connections to a minimum
/// 2. guarentees that the connections are all made to the same server.
/// 3. keeps the username and password so that the user doesn't need to
/// login for every single connection.
/// 4. allows the different modules to all access a single webservice.
///
/// </summary>
public class SingleWS
{
private static SingleWS singleWS = null;
private static webServicesService ws;
private static string username;
private static string password;
private SingleWS()
{
ws = new webServicesService();
}
private static void setAuthentication()
{
CredentialCache myCache = new CredentialCache();
NetworkCredential myNetWorkCredential = new NetworkCredential(username, password);
myCache.Add(new Uri(ws.Url), "Basic", myNetWorkCredential);
ws.Credentials = myCache;
}
public static webServicesService getInstance(string Url)
{
if(singleWS == null)
singleWS = new SingleWS();
if(Url != null && !Url.Equals(""))
if(!ws.Url.Equals(Url))
ws.Url = Url;
setAuthentication();
return SingleWS.ws;
}
public static string Username
{
set{username = value;}
}
public static string Password
{
set{password = value;}
}
}
}
See more files for this project here