Can a C# application communicate with Node.js code?
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. Is this possible?
Edit: Both applications run on the same machine. The C# application would provide three arguments to the Node.js application. The Node.js application would query a web service (POST), receive some XML data, and manipulate that data. I know that I could do that task in C# too, but in this case it has to be Node.js.
Edit #2 and solution: Right now I have chosen:
4. Your node process runs a socket server and your C# app does requests over tcp.
I will also provide a solution that seems to work:
- Node.js part: http://www.hacksparrow.com/tcp-socket-programming-in-node-js.html
- C# part: http://www.codeproject.com/Articles/1415/Introduction-to-TCP-client-server-in-C
Now you are ready to send any data from your C# application to the Node.js server.
Yes communication is possible like several people have pointed out in your question's comments.
These are (some of) the options:
- Your node process runs an http server and your C# app does JSON Rest requests over http
- Your node process runs a SOAP webservice using the node-soap module
- C# app starts your node app and you do IPC by writing to the node process inputstream and read it's outputstream.
- Your node process runs a socket server and your C# app does requests over tcp.
- You use a 3rd process/server like Redis or a Message Queue
- 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.