1

I have made simple chat application to learn some new things, and what I want to do now, is to add user list that are currently logged into chat. So I did this:

        public ObservableCollection<User> GetUserList()
    {
        ObservableCollection<User> users = new ObservableCollection<User>();

        IEnumerable<User> userEnu;
        userEnu = from u in _clientDic
                  select new User
                  {
                      UserName = u.Key
                  };

        foreach (User user in userEnu)
        {
            users.Add(user);
        }

        IEnumerable<IDuplexClient> clients;
        clients = from p in _clientDic
                  select p.Value;

        foreach (IDuplexClient item in clients)
        {
            item.DisplayUserList(users);
        }
        return users;
    }

There is also DataConctract that coressponding to User. Anyway. This method get all users that are present in dictionary and put them into ObservableCollection.

What I want to do, is to push data from this collection to user, if it change (users log or logout).

So far I only managed to manually pull data from Server by calling

_client.GetUserListAsync()

manually. Trough pushing button in silverlight app. But that's not why I'm using duplex connection, to force user (or client app) for perdiodic calls to server, that check if there is new data or not. I want server to push any new data to client.

    [ServiceContract]
public interface IDuplexClient
{
    [OperationContract(IsOneWay = true)]
    void DiplayMessage(string message);

    [OperationContract(IsOneWay = true)]
    void DisplayUserList(ObservableCollection<User> userColl);
}

And here is service contract. Honestly I don't really know if this is relevant, but I post it just in case.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Łukasz Baran
  • 1,229
  • 3
  • 24
  • 47

1 Answers1

0

you can do that using pollingDuplexHttpBinding Check this

Subhash Lama
  • 433
  • 2
  • 12
  • I know. That's how I did my sample chat application. Send messages between users is not problem. Real problem here is how to make server push data from Collection (wheter is pulled from DataBase with LINQ or from Dictionary). Unforutnelty I can't send data from collection in the same manner as I'm sending ordinary text messages between users. What I wan't to do is make server check collection if there are any changes in it, if there are, push those changes to all clients that are intrested (same room, channel, game etc) – Łukasz Baran Apr 20 '11 at 15:47