tags:

views:

118

answers:

1

I have a server that needs to keep a small number of clients in sync. Whenever there is a change of state at the server, all the connected clients must be informed.

  • I am planning to use a “callback contract”,
  • I can get hold of the callback reference for each client on the server by using GetCallbackChanel().
  • I then need to manage all these client channel reference and call all of them when needed.

So far so good however:

  • I don’t wish to block the server, so calls to the clients must be none blocking
  • Errors calling the client must be logged and coped with

Is there a standard WCF component to do this?

+2  A: 

No, there is not a standard WCF component for this, at least through .NET 3.5. I can't speak to what may be available in .NET 4.0.

That said, there is a pretty straightforward way to do this. Juval Lowy, author of Programming WCF Services, describes how to do this using his WCF-based Publish-Subscribe Framework.

Basically, the idea is to create a separate WCF event service that resides in the same hosting application as your server (e.g., Windows service, IIS). When the state of your server changes, you publish the state change to the event service. The clients that need to be kept in sync subscribe to this same event via the event service. In effect, the event service becomes a broker for your server to notify clients of whatever events your server publishes.

The article I listed above has a code download, but you can also get the Publish-Subscribe Framework and a working example for free from his website, IDesign.net. Here is the link to the download. You may need to scroll your browser up just a little bit to see it as I believe their internal hyperlink is wrong.

Matt Davis