简体   繁体   中英

Can you send data to clients from a WCF service without the clients having to call the service?

Say I want to write a peer to peer chat application. And I use a WCF service as the server that the clients 'log in' to so that they can find each other's ip addresses and ports.

Well, say also I have a textbox in my client application that display all users that are online. Everytime users log in or out I want to update this 'Who's online' textbox so that only the currently online users are shown.

So the server needs to send information out to all clients once a user logs in or out. But it seems WCF can only send data when responding to requests....

Am I missing something here, is WCF able to handle this situation?

我认为你需要双工服务。

There are several approaches to this problem, these would probably be the most common:

  1. Use publish/subscribe, like in this good article .
  2. Keep all the currently logged users in a storage - a database or whatever you'd prefer, and query it from the users' side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM