开发者

Event Dispatcher for WCF call-backs

开发者 https://www.devze.com 2022-12-12 12:08 出处:网络
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 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 c开发者_如何学Component to do this?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号