How to push data (SQL or LINQ), from WCF Duplex Service to Silverlight client
I have made simple chat application to learn some new thin开发者_StackOverflow社区gs, 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.
you can do that using pollingDuplexHttpBinding
Check this
精彩评论