Click here to Skip to main content
Click here to Skip to main content
Go to top

Chat Application using Web services in C#

, 15 May 2008
Rate this:
Please Sign up or sign in to vote.
This is a cool chat application created in DotNet using web services having all the functionalities.


All of us are more or less using many of the chat applications available in the market everyday but still sometimes wonder of how it has been developed. This is a simple private chat application developed in DotNet using a web service.

The application (EasyTalk, I named it) targets mainly the beginners who still sometimes fear of using the web service. The audience will get a taste of how web servcie can be easily developed and can be used in a chatting application.


The chat client is developed just like any other chat application using Windows form and the chat service is developed using the Dot Net web service residing in the web server.

Zip File Contents

The above attached zip file contains the following projects:

1. Chat Service - This is the web service to be deployed in any web server.

2. Chat Client - The is the chat application through which the user will chat.

3. Chat Setup - The distributable setup package.

4. Chat Testing - To is to test the web service.

Using the code

ChatService.asmx (Web Service)

The ChatService.asmx in the zip file represents the name of the web service in which you will see lot of web methods that will be called by the clients using the application.

[WebService(Namespace = "<a href="%22%22"></a>")]
[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 

Remember these methods are always 'public', otherwise they won't be available for the outside world. You can only set a public method as a web method, otherwise they will be treated as private methods to the web service.

Let us walk through some of these methods:

public void AddUser(string strUser)

The AddUser() method will add the user who has logged in the ArrayList being maintained in the web service. By this way the online user list is always updated and will give you the list of users in the room at any point of time.

public string GetUsers() 
    string strUser = string.Empty; 
    for (int i = 0; i < arrUsers.Count; i++)
        strUser = strUser + arrUsers[i].ToString() + "|";
    return strUser;

The GetUser() method will retrieve the list of users who have logged in the application. This list can be easily available from the Arraylist at any time.

public void RemoveUser(string strUser)
    for (int i = 0; i < arrUsers.Count; i++)
        if(arrUsers[i].ToString() == strUser)

The RemoveUser() method will do the opposite. It will take out the required name out of the Arraylist whenever the user logout from the application.

public void SendMessage(string strFromUser, string strToUser, string strMess)
    arrMessage.Add(strToUser + ":" + strFromUser + ":" + strMess); 

The SendMessage() method will concatinate the strings (the username to which the message has been sent, the username who has sent the message and the actual message) coming as parameters and will add the new string to another ArrayList. This ArrayList will simply hold all the messages coming from diferent clients intended for different users.

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] + ":";
    return strMess;

The ReceiveMessage() method is doing all the tricks. It will filter the messages from the Arraylist and will send each message to its actual recipient.

1. It is taking out the messages one by one from the Arraylist.

2. It is comparing the 'ToUser' name attached with the message with the username from whom the method is requested.

3. If the names are same means the message is intended for that recipient only. It will return the message to that user and remove the message from the arrayList once it is transfered.

ChatClient (Client Application)

Chat User List Window

The Chat Client is developed using the Windows Forms. You will see two forms by the name Form1 for showing the online user list and PrivateMessage for the chat window.

In this solution we have added the web service as a web reference to this project. So whenever you add the web service that has been deployed in any of your server, the client application will register that path to the server.

The Form1 is the interface that is populating the list of online users logged into the EasyTalk aplication. There is no login form in this application as the username is automatically assigned from the windows login name. The same name will get displayed in the list which on click will open a one to one conversation window to chat with that person. There is a timer attached with this form that will call the GetUser() web method in the web service every 2 seconds to update the list of online users.


Extra Functionalities:

1. Whenever any user logs into the application, a notification window will get popup in all the online users machine from the right corner of the screen to show the name of the new online user. [screenshot below]


2. Whenever the user minimises the chat window, the new messeges will start coming to that user in a popup window like the one above from the right corner of the screen like that in gtalk.

3. If the user wishes not to get the messeges in apopup window he can select the checkbox at the bottom of the main window named "Stop Messege Alert service".

Chat Window

The other form is the privateMessage that will allow the user to talk to the other person. There is also a timer attached with this form that will call the ReceiveMessage() method to check whether any new message has arrived from the other side. So if there are 3 windows open for an user, the respective window will look for it's own message through the timer.

Private Message

In the application, the notifyIcon control is also used so that the user can keep the application running in the system tray. There is a menu associated with the application through which the

One catchy thing that has been used in this application is to blink the chat window whenever any new message comes. The blinking will go on till the user clicks the window to read the message. This is done using Windows API.

static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);

Configuration Window

There has been a configuration window to change the server name/ip address. If the web service is deployed in a diferent chat server, only the new ip addreess needs to be supplied to the application through the configuration window by the users.

Points of Interest

This is just one way of creating a very simple chat application using a web service. You can create this application using a different approach. You can further procced with this application by creating more functionalities like Public Chatting, Conferences, etc.

Happy Chatting!!!!!!


Keep a running update of any changes or improvements you've made here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Surajit Paul
Team Leader
United States United States
He has a total experience of more than 6 years in programming on different technologies. Currently working as a Systems Analyst.

Comments and Discussions

Questioncant download... PinmemberMember 103012517-May-14 21:11 
QuestionNo Puedo Ejecutar la Aplicación HELP Pingroupjuan_2001-Apr-14 18:47 
GeneralMy vote of 5 Pinmemberthedinesh0125-Mar-14 0:03 
QuestionGood work PinmemberRaghbinho19-Mar-14 4:17 
QuestionImplement Group Pinmembersachin.vishwa9023-Jan-14 19:00 
Questionunable to run Pinmemberatul singh rautela20-Nov-13 19:12 
GeneralMy vote of 5 Pinmemberterdia27-Aug-13 6:32 
QuestionError in connecting to the chat server Pinmemberterdia27-Aug-13 6:25 
AnswerRe: Error in connecting to the chat server Pinmemberpalespyder20-Sep-13 8:37 
BugWhile Building the Project gets error! Pinmembermuhammed riyaaz29-Apr-13 18:45 
Questionhow to run all these four application Pinmemberbaskaran chellasamy28-Apr-13 22:01 
Questionadding voice chat to easy talk chat application Pinmembervj2714-Apr-13 20:17 
AnswerRe: adding voice chat to easy talk chat application Pinmemberbaskaran chellasamy28-Apr-13 22:04 
QuestionRe: adding voice chat to easy talk chat application Pinmemberjain_ravi9-May-13 0:23 
Questionvoice chat in with easy talk chat application Pinmembervj279-Apr-13 20:21 
QuestionRe: voice chat in with easy talk chat application Pinmembermuhammed riyaaz3-Jun-13 21:48 
SuggestionVisual Studio 2010 compatibility PinmemberFourCrate11-Oct-12 11:45 
GeneralMy vote of 5 Pinmemberiadh0096-Feb-12 23:41 
QuestionExecuting Client PinmemberTKCA25-Jan-12 21:29 
Questionhow is Arralist dll implemented. PinmemberMember 381561630-Dec-11 15:43 
Questionchat Software Pinmemberom_metab14-Dec-11 1:06 
Questionhow should i attach this application to my project Pinmemberpal5hah29-Nov-11 18:56 
Questioni think you have a problem in get user Pinmembermostafa.elsadany10-Sep-11 21:00 
QuestionPLEASE HELP...I GET ERRORS PinmemberUNOWN30126-Aug-11 8:27 
So I am just trying to get the test application running right now and this is what I get in the messagebox error when I do anything:
Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'.
The request failed with the error message:
<title>Configuration Error</title>

<img src='' border=0>

Your web site is expired or has a configuration problem. Please login to your account in and make sure your site is configured correctly.

Share your knowledge and earn revenue

AspSpider team is launching a new platform for Windows computer users to share knowledge and earn the AdSense revenue. In association with Google,
we are introducing a AdSense revenue shring system where we use AdSense APIs to share 90% of the AdSense revenue to the
contributing member from the content pages. Visit for more details.

<!-- 336x280 Rectangle AdSense Ad Tag Start -->
<!-- 336x280 Rectangle Ad Tag End -->

Make sure you have not disabled impersonation in your web.config file. Impersonation is enabled by default.

To enable impersonation, remove the tag from your web.config or specify the value impersonate="true".

If you have the identity tag in your web.config, it must look like the

Current contests and reward programs in

First Diamond Awards

<img src='' align='left'>First few members who reach diamond level will win great prizes. prizes include High Definition
(HD) camcoder, Digital camera and Electronic gadgets.
Learn more about First Diamond Awards

Star of The Club Award

<img src='' align='left'>From time to time, we will select some of our super stars as "Star of The Club". This award comes
with a recognition certification.
See more details about the Star of The Club Award

Member of the Month

<img src='' align='left'>Every month, we will select a winner based on the overall contribution and points
earned during the month. The winner will receive an award of excellence, along with cash credits and extra points.
Read more about Member of The Month award

AdSense Welcome Bonus

<img src='' height='40' align='left'>MWC can create Google AdSense accounts on behalf of members using
Google AdSense APIs. This is a program we are running in association with Google. If you create an AdSense account through MWC and get approval from Google, we will give you Rs 100 AdSense welcome bonus

Profit sharing and site partnership offer

<img src='' align='left'> Top 10 contributors of this site will earn 100% of the
revenue from this site during first year.
Read more about becoming part of the team and taking the revenue

Referral Bonus

<img src='' align='left'>Bring your friends to MyWindowsClub and earn up to Rs 500 if they reach higher levels here.
Read more about Referral bonus programs.

Blog Contest

<img src='' align='left'>Write blogs about MWC in your personal blog and win some great prizes.
See more details about the blog contest

AdSense revenue sharing

<img src='' height='40' align='left'>All GOLD level and above members are eligible for this. You will
receive 90% of the Google AdSense revenue from your content pages for a period of 1 year from the date of each post. If you spend few hours every week, it is quite easy to earn couple of hundred
dollars every month from AdSense.
Learn more about Google AdSense revenue sharing.

Get paid for posting answers in other sites

We pay money of you post answers in other popular sites with some reference to MyWindowsClub.
Learn more about earning money by posting in other sites

Remember, member posts are eligible for cash credits based on quality, which is an addition to all of the above benefits.

<!-- LakeQuincy -->
<script type='text/javascript'>//<![CDATA[
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='' type='text/javascript' %3E%3C/script%3E"));
<script type='text/javascript' language='Javascript' src=''></script>
<script type='text/javascript' language='Javascript'> if($.LqmAds)$.LqmAds();</script>
<!-- End: LakeQuincy -->
GeneralProblem in deplying webservice on remote server Pinmemberkuldeepdangi9-Apr-11 4:35 
GeneralGreat Article Pinmembervmaxp2-Mar-11 22:40 
Questionfailed to save in config file Pinmembert srinivasa20-Feb-11 18:20 
AnswerRe: failed to save in config file PinmemberParam2823-Apr-11 17:52 
GeneralPlz Reply Its vry vry Urgent..... [modified] PinmemberWebgur19-Feb-11 2:06 
GeneralRe: Plz Reply Its vry vry Urgent..... [modified] Pinmembervenkatrupa18-Mar-14 5:28 
GeneralInconsistent accessibility [modified] PinmemberWebgur19-Feb-11 0:27 
Generalquestion regarding chat server Pinmemberpavanbajaj9-Oct-10 9:23 
GeneralA free web chat service for your reference ... Pinmembermohangupta138-Oct-10 22:30 
GeneralMy vote of 5 Pinmembersamunder14-Jul-10 22:02 
GeneralInconsistent accessibility Pinmemberb_s_priyaa15-May-10 1:49 
GeneralRe: Inconsistent accessibility Pinmemberchamarajanakadanthanarayana8-Sep-10 17:51 
Generalplease solve this proble PinmemberSubhash0203888-Apr-10 11:49 
GeneralUnable to send message using chat application. PinmemberMember 32850044-Mar-10 6:18 
Generalhelp me to dibug this Pinmemberanandk1209873-Feb-10 6:15 
QuestionInconsistent accessibility Error any advice? Pinmemberadam parnell29-Jan-10 10:17 
GeneralIn need of your suggestions. Pinmemberslimtugo6-Aug-09 2:20 
GeneralUnable to run the downloaded application Pinmembernainakarri3-Aug-09 21:34 
QuestionFile Transfer and Conference Pinmembermroberto200822-Jun-09 9:52 
GeneralConference PinmemberJobin Daniel27-May-09 20:33 
GeneralRe: Conference PinmemberKennie_n20008-Dec-09 9:11 
GeneralRe: Conference Pinmemberronaldovn7-Mar-10 20:15 
GeneralWebservice not working Pinmemberadam parnell14-May-09 7:00 
Questionhow setup this program? Pinmemberqomcse22-Apr-09 5:04 
AnswerRe: how setup this program? PinmemberKennie_n20008-Dec-09 9:28 
QuestionProblem with using this Chat Application Pinmembermalli.reddy.mca16-Apr-09 2:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 16 May 2008
Article Copyright 2007 by Surajit Paul
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid