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

查看:154
本文介绍了的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.

有一些意见(客户端),这将受益于现场互动,同时涉及推拉,因此而不是实现某种自定义的长轮询或asp.net的WebSocket服务器的一些UI元素,我期待Node.js的杠杆为Windows和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.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)可以使POST请求的Node.js(HTTP),并在这个过程中发送一个auth-关键要格外安全。就像1)节点会发生反应,你发送的数据。

3)使用像 Redis的的发布 - 订阅,从ASP.NET(酒馆)发送消息,并让他们的节点。 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天全站免登陆