|
using System;
using System.Web;
using System.Data;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ChatService : System.Web.Services.WebService
{
static protected ArrayList arrUsers = new ArrayList();
static protected ArrayList arrMessage = new ArrayList();
public ChatService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string GetUsers()
{
string strUser = string.Empty;
for (int i = 0; i < arrUsers.Count; i++)
{
strUser = strUser + arrUsers[i].ToString() + "|";
}
return strUser;
}
[WebMethod]
public void AddUser(string strUser)
{
arrUsers.Add(strUser);
}
[WebMethod]
public void RemoveUser(string strUser)
{
for (int i = 0; i < arrUsers.Count; i++)
{
if(arrUsers[i].ToString() == strUser)
arrUsers.RemoveAt(i);
}
}
[WebMethod]
public void SendMessage(string strFromUser, string strToUser, string strMess)
{
arrMessage.Add(strToUser + ":" + strFromUser + ":" + strMess);
}
[WebMethod]
public string ReceiveMessage(string strUser)
{
string strMess = string.Empty;
for (int i = 0; i < arrMessage.Count; i++)
{
string[] strTo = arrMessage[i].ToString().Split(':');
if (strTo[0].ToString() == strUser)
{
for (int j = 1; j < strTo.Length; j++)
{
strMess = strMess + strTo[j] + ":";
}
arrMessage.RemoveAt(i);
break;
}
}
return strMess;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
He has a total experience of more than 6 years in programming on different technologies. Currently working as a Systems Analyst.