Communicating between Node.Js and ASP.NET MVC Application

前端 未结 2 1419
心在旅途
心在旅途 2021-01-12 06:36

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 languag

相关标签:
2条回答
  • 2021-01-12 06:57

    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?

    You can try to look at redis pub/sub model where ASP.NET MVC application and node.js would communicate through separate channels in order to achieve full-duplex communication. Or you can also try to use CouchDB change nofitications.

    I also know that you could use a database inbetween but surely this would need to be polled and would be less efficient?

    Former techniques do not require you to poll for changes, but instead they will notify you when the changes happens or channel message arrives.

    0 讨论(0)
  • 2021-01-12 07:19

    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.

    0 讨论(0)
提交回复
热议问题