Can a C# application communicate with Node.js code?

前端 未结 2 396
再見小時候
再見小時候 2020-12-13 04:08

I have a C# application and a Node.js application. I would like to press a button in my C# application to send three arguments to a Node.js application/function as input. I

2条回答
  •  隐瞒了意图╮
    2020-12-13 04:40

    Yes communication is possible like several people have pointed out in your question's comments.

    These are (some of) the options:

    1. Your node process runs an http server and your C# app does JSON Rest requests over http
    2. Your node process runs a SOAP webservice using the node-soap/strong-soap module
    3. C# app starts your node app and you do IPC by writing to the node process inputstream and read it's outputstream.
    4. Your node process runs a socket server and your C# app does requests over tcp.
    5. You use a 3rd process/server like Redis or a Message Queue
    6. Anything that allows you to share data like files..

    I would recommend you go for the first option as that doesn't require you to define a language protocol to send over the "wire". The other reason would be that there is a lot of documentation available on doing Rest with C# and node.js.

    As the client library in C# I would suggest you have a look at Restsharp as the client library if you can't use the latest version of .NET (4.5). If you can use the latest version, use HttpClient to call your Node.js restservice. For Node just use Express.

    Option 2 might be quick as there is good support in VS for webservices, however, I have only used node-soap as a client so can't comment on how well the node-soap webservices are with C# clients.

提交回复
热议问题