如何通过互联网实现发布/订阅通信

发布于 2024-09-25 02:51:42 字数 648 浏览 6 评论 0原文

我有一个托管在服务器上的 .Net 服务,以及通过互联网连接到该服务器的 .Net 客户端。

我想实现一个发布订阅模型,客户端可以订阅服务上的事件,并在数据可用时将数据推送给它们。另一种方法是让客户端轮询服务器以获取数据,但这对于所需的数据来说可能太慢。因此需要发布/订阅类型的通信。

我知道 WCF 绑定 WSDualHttpBinding 确实允许这样做,但它有一个缺点。根据《WCF 服务编程》作者 Juval Lowy 的说法,

...WSDualHttpBinding 主要是 无法使用,因为它实际上是 不可能通过各种隧道 沟通障碍将彼此隔开 客户的服务和需求 查找特定的网络服务器机器 这使得这不切实际。

我将此解释为(如果我错了,请纠正我)要使用 WSDualHttpBinding 进行操作,客户端有必要在其计算机上打开一个端口(以及任何必要的路由器配置)以便服务器进行回调。如果是这种情况,使用 WSDualHttpBinding 将不是我的选择。使用 Windows Azure 也不是一个选择。

所以我的问题的关键是,如何通过互联网实现发布/订阅/回调类型的通信,而不需要在客户端计算机上打开端口?开放标准可以,但没有必要,因为客户端和服务器都是.Net,Windows Azure 不是一个选项。

I have a .Net service hosted on a server, and .Net clients connecting to this server over the internet.

I want to implement a publish subscribe model where clients can subscribe to events on the service and have data pushed to them as data becomes available. An alternative would be to have clients poll the server for data, however this will likely be too slow for what is required. Hence the need for a publish/subscribe type of communication.

I understand that the WCF binding WSDualHttpBinding does allow this, however it comes with a downside. According to "Programming WCF Services" author Juval Lowy,

...the WSDualHttpBinding is mostly
unusable, since it is practically
impossible to tunnel through various
communication barriers separating the
service from the client and the need
to find a specific web-server machine
makes this impractical.

I've interpretted this to mean (please correct me if I'm wrong) that to operate with WSDualHttpBinding, it is necessary for clients to open a port on their machines (along with any necessary router configuration) for the server to callback through. If this is the case using WSDualHttpBinding will not be an option for me. Using Windows Azure will also not be an option.

So the crux of my question is, how can I achieve a publish/subscribe/callback type of communication over the internet, without the need to open ports on the client machine? Open standards are ok but unnecessary as client and server are both .Net, Windows Azure is not an option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

可遇━不可求 2024-10-02 02:51:42

WSDualHttpBinding 包含两个通道,第一个从客户端到服务器,第二个从服务器到客户端。后一种确实需要防火墙和NAT配置。 Net.Tcp 怎么样?它仅使用单个通道,并支持通过该通道从客户端到服务器发起的回调(双工通信)。您提到客户端和服务器都是 .NET 应用程序,因此应该可以在服务器上进行一些防火墙配置。

WSDualHttpBinding contains two channels one from client to server and second from server to client. The later one indeed requires firewall and NAT configuration. What about Net.Tcp? It uses only single channel and supports callbacks (duplex communication) over that channel initiated from client to server. You mentioned that both client and server will be .NET application so it should be possible with some firewall configuration on the server.

爱人如己 2024-10-02 02:51:42

您在帖子中提到了大多数选项。

有 3 个选项:

  • 客户端轮询服务器。不需要开放端口,但速度太慢。
  • WSDualHttpBinding 需要打开
  • Azure 服务总线端口,可以这样做,但不是一个选项。

实际上有一种方法可以做到。如果您了解 Azure 服务总线的工作原理,您会发现它会欺骗客户端,让其认为它位于传出端口上,而实际上它用于向客户端发送消息。你可以尝试实现这个功能。

您可以尝试的另一件事是 nservicebus,位于 http://nservicebus.com/,这是一个开源 .net 服务总线。

You mention most of the options in your post.

There are 3 options:

  • Client polls the server. Does not require open ports but too slow.
  • WSDualHttpBinding requires opening of ports
  • Azure Service Bus, would do it but not an option.

There is actually a way to do it. If you look at how Azure service bus works, it tricks the client into thinking that it is on an out going port, when really it being used to send messages to the client. You could try to implement this functionality.

Another thing you could try is nservicebus at http://nservicebus.com/, this is an open source .net service bus.

卷耳 2024-10-02 02:51:42

Internet 通信引擎 (ICE) 提供IceStorm,一种发布/订阅服务

它是开源的,如果您下载安装程序,则会有一个示例 Visual Studio 项目演示如何实现发布/订阅(查看“demos”.zip 文件和带有时钟演示的“IceStorm”目录)。

ICE 将为您完成所有繁重的工作,学习曲线非常短,主要是因为文档量大、平易近人且写得很好。

Internet Communication Engine (ICE) offers IceStorm, a publish/subscribe service.

Its open source, and if you download the installation there is a sample Visual Studio project that demonstrates how to implement publish/subscribe (check out the "demos" .zip file and the "IceStorm" directory with the clock demo).

ICE will do all the heavy lifting for you, the learning curve is remarkably short, primarily because the documentation is massive, approachable and well written.

知你几分 2024-10-02 02:51:42

我强烈推荐您通过互联网进行 DDS(OMG 的数据分发服务)http://www.omg.org/news/meetings/workshops/Real-time_WS_Final_Presentations_2008/Session%203/03-02_Bertocci_et_al.pdf

来自 OMG,这就是我要说的。是的,我知道你可能认为 OMG 已经结束了。我不这样做,作为一名政府顾问,我确实推动标准。请记住,除了自由主义意识形态和危机之外,政府仍然是一个巨大的客户,互操作是必须的。

N服务总线?好吧,好吧,但是现在开始是不是太复杂了?学习曲线太...陡峭?我想不是,但是,还有更简单的吗?

ICE是一个不错的选择。来自 CORBA 世界的人们正在努力让事情变得更好。不要怀疑,使用它,尝试一下!只是一种感觉:即使使用风暴服务,您可能会觉得自己仍然处于请求/回复的世界中......但这是一个骗局吗?


但是,如果您更喜欢商业但开放的解决方案,请考虑使用协议缓冲区发布订阅(搜索 Google 协议缓冲区)...只是第一种方法 http://protocolbus.casessite.org。这是我的 owm 工作...抱歉,这只是一个初始项目,但我正在使用中央代理分发作为替代传输(默认为多播,但广播和 udp 也可用)。开源,所以免费......

I strongly recommend you DDS (data distribution service from OMG) over the internet http://www.omg.org/news/meetings/workshops/Real-time_WS_Final_Presentations_2008/Session%203/03-02_Bertocci_et_al.pdf

From OMG, that's all I gotta say. Yes, I know you may think OMG is over. I don't, and as a government counselor I really push for standards. Keep in mind that besides the liberal ideology and crises, governments are still a huge customers and inter-operation is a must.

NServiceBus? Right, ok, that's fine, but ain't too complex to start right now? Learning curve is too ... steep? I guess is not but, any easier one?

ICE is a good choice. guys from CORBA world trying to make things better. Don't doubt it, use it, try it! Just a feeling: even with the storm service you might feel you are still in the request/reply world ... but is that a con?


But if you rather prefer a commercial but open solution, think about publish subscribe using protocol buffers (search Google protocol buffers) ... just a first approach http://protocolbus.casessite.org . This is my owm work ... sorry it's just an initial project but I'm working with a central broker distribution as an alternative transport (default is multicast but broadcast and udp is also available). Open source, so be free ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文