Node.Js 和 ASP.NET MVC 应用程序之间的通信 [英] Communicating between Node.Js and ASP.NET MVC Application

查看:18
本文介绍了Node.Js 和 ASP.NET MVC 应用程序之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 ASP.NET MVC 构建的现有复杂网站,包括数据库后端、数据层以及 Web UI 层.用另一种语言重建这个网站不是一个可行的选择.

I have an existing complex website built using ASP.NET MVC, including a database backend, data layer, as well as the Web UI layer. Rebuilding this website in another language is not a feasible option.

在某些视图(客户端)上有一些 UI 元素可以从实时交互中受益,包括推和拉,所以我希望在 asp.net 中实现某种自定义长轮询或 websocket 服务器,而不是利用适用于 Windows 的 node.js 和 Socket.io.

There are some UI elements on some views (client side) which would benefit from live interactivity, involving both push and pull, so rather than implement some kind of custom long polling or websocket server in asp.net, I am looking to leverage node.js for Windows, and Socket.io.

我的问题是我需要在两个应用程序之间进行双向通信.每个用户只有在 ASP.NET 网站上获得授权后才能接收数据,因此我首先需要为此进行通信.其次,一旦 ASP.NET 网站上发生某些事件,我想立即将这些数据推送到 Node 服务器,以广播给特定用户或用户组.第三,我希望将发送到 node.js 服务器的任何数据推送到 ASP.NET 网站进行处理,因为这是我们所有业务逻辑所在.添加 Node.js 的唯一原因是有可能将数据直接推送到客户端,我不想在其中构建任何业务逻辑(或尽可能少).

My problem is that I need two way communication between both applications. Each user should only be able to receive data once they are authorised on the ASP.NET website, so I first need communication for this. Secondly, once certain events occur on the ASP.NET website I want to immediately push this data to the Node server, to be broadcast to specific users or groups of users. Thirdly, I would like any data sent to the node.js server to be pushed to the ASP.NET website for processing, as this is where all our business logic lies. The sole reason for adding Node.js is to have the possibility to push data directly to the client, I do not want to build any business logic into it (or as little as possible).

我想知道 Node.Js 和 ASP.NET 之间双向推送通信最快的方法是什么.到目前为止,我知道的唯一好的选择是在 node.js 服务器上的特定端口上创建一个特殊的侦听器并连接到它,但我想知道是否有更优雅或更有效的方法?我也知道您可以在两者之间使用数据库,但肯定需要轮询并且效率会降低吗?两台服务器将在 Visual Studio 项目下的同一台服务器上运行.

I would like to know what the fastest method of two-way push communication is between Node.Js and ASP.NET. The only good option I'm aware of so far is to create a special listener on a specific port on the node.js server and connect to that, but I was wondering if there's a more elegant or more efficient method? I also know that you could use a database inbetween but surely this would need to be polled and would be less efficient? Both servers will be running on the same server under a Visual Studio project.

非常感谢您提供的任何帮助.

Many thanks for any help you can provide.

推荐答案

我不是 ASP.NET 专家,但我认为有多种方法可以实现这一点:

1)正如您所说,您可以让节点在特定端口上侦听数据,然后根据收到的数据(TCP)做出反应
2) 您可以向 Node.js (HTTP) 发出 POST 请求,并在此过程中发送一个 auth-key 以提高安全性.就像 1) 节点会对您发送的数据做出反应.
3) 使用诸如 Redis 之类的东西进行发布-订阅,从 ASP.NET (pub) 发送消息并在节点上获取它们.js 部分(子).如果您想在多台机器上扩展您的应用程序,这会更好.

I'm not an ASP.NET expert, but I think there are multiple ways you can achieve this:

1) As you said, you could make Node listen on a specific port for data and then react based on the data received (TCP)
2) You can make POST requests to Node.js (HTTP) and also send an auth-key in the process to be extra-secure. Like on 1) Node would react to the data you send.
3) Use something like Redis for pub-sub, send messages from ASP.NET (pub) and get them on the Node.js part (sub). This is even better if you want to scale your app across multiple machines etc.

这篇关于Node.Js 和 ASP.NET MVC 应用程序之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆