本文介绍了需要向客户端推送消息的 WCF Service的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我需要的设计:实现开始,如果您是愿意接受它的权衡(必须是 WCF 客户端,您拥有客户端和服务)和限制(客户端直接耦合,网络拓扑限制).

如果双工通道的限制不符合您的喜好,那么您可以考虑使用诸如 MSMQ 或 NServiceBus 促进发布/订阅要求.您可以使用 Windows Azure AppFabric 服务总线.

Duplex 可以独立地向客户端发送消息,而不仅仅是在来自客户端的呼叫到达时.

双工不持久 - 当客户端消失或出现任何通信问题时,您必须从通道故障中恢复.保护双工可能很棘手.您必须在双方都有 WCF 客户端/服务.您必须了解您的网络拓扑.

您有 2 个不同的绑定上下文(系统).一种是让客户端发送命令和查询,另一种是将有趣的事件发布给想要收听这些事件的人.

编辑 - 如果某些客户端是 iOS 设备怎么办?使用双工会带来问题吗?您能否开发一个通过 DUPLEX 通道与 WCF 服务通信的 iOS 应用程序?

答案:请参阅此 SO iPhone 上的 WCF 双工连接?在开发可互操作的 WCF Web 服务时我应该知道什么?

This is the design I need : My design idea.

Is the 'Subscriber' design a good idea for the 'orange' part of the service ?

Clients needs to connect to the service to perform 'read' and 'write' operations, and they also need to get notifications (in a PUSH manner) from the service.

At the beginning I thought that the service that provides the 'read' and 'write' functionialliyy will be able to send notifications also (via a background thread), but then I understood that 'CallBack' is only used when a service needs to call functions on the client as a reponse for a client's request . Meaning - the service cannot initiate a call to the client. So is the 'Subsciber' design the correct way to go at this ?

解决方案

So short answer is yes - using publish/subscribe pattern is very well known model. It helps with decoupling consumers from publishers. Devil is in the implementation details and how much complexity can you handle and what are you willing to trade in your design.

You could start with WCF duplex channel implementation if you are willing to accept it's trade offs (must be WCF client, you own client and service) and limitations (clients directly coupled, network topology limitations).

If the limitations of duplex channel is not to your liking then you can look into using something like MSMQ or NServiceBus to facilitate pub/sub requirements. You can take it to the next level with Windows Azure AppFabric Service Bus.

Duplex can send messages to the client independently not just when call from client arrives.

Duplex is not durable - you got to recover from channel failure when client goes away or there are any communication problems. Securing duplex can be tricky. You have to have WCF client/service on both sides. You have to be aware of your network topology.

You have 2 different bound contexts (systems). One is for the clients to send commands and query and the another one is for publishing interesting events to who ever want's to listen to these events.

EDIT - What if some of the clients are iOS devices ? Would using a DUPLEX pose a problem ? Can you develop an iOS app that communicates to a WCF service via a DUPLEX channel?

Answer: See this SO WCF duplex connection on iPhone? and What should I know when developing interoperable WCF web service?

这篇关于需要向客户端推送消息的 WCF Service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 05:33
查看更多