C# Chat Application
First web service project
ClassOBJ.cs class code
//public class ClassObj
//{
//public
ClassObj()
//{
// }
public int ID { get; set; }
public String Message { get;
set; }
//}
ListObj.cs class code
public class ListObj
{
public
ListObj()
{
}
public static List<ClassObj> _listObj = new
List<ClassObj>();
}
Service.cs code
public class Service :
System.Web.Services.WebService
{
public
Service () {
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public List<ClassObj>
Chat( int _id ,String
_Msg)
{
ClassObj
obj = new ClassObj();
obj.ID =_id;
obj.Message = _Msg;
ListObj._listObj.Add(obj);
return ListObj._listObj;
}
[WebMethod]
public void
ChatClear()
{
ListObj._listObj.Clear();
}
}
Second client application
Firstly
add reference
Clear
button event
ServiceReference1.ServiceSoapClient client = new ServiceSoapClient();
client.ChatClear();
ListBox1.Items.Clear();
Chat
button event
ServiceReference1.ServiceSoapClient client = new ServiceSoapClient();
ServiceReference1.ClassObj[] _classObj = client.Chat(Convert.ToInt32(TextBox1.Text), TextBox2.Text);
String
ss = "";
ListBox1.Items.Clear();
for (int i = 0; i < _classObj.Count(); i++)
{
ListBox1.Items.Add(_classObj[i].ID.ToString());
ListBox1.Items.Add(_classObj[i].Message.ToString());
}
No comments:
Post a Comment