How to control a C# Program from the web? Using AJAX maybe?
Can anyone explain how to send variables from the web (PHP, Javascript, etc.) to a C# program? I want to allow the web to tell the program what to do. Maybe I could use AJAX to send data to an auto-updating page, which the C# program can then read? That would also allow users to be logged-in to the page and therefore different data could be s开发者_C百科ent to each user. Could someone explain how this could be done?
You could build a webservice in .NET. The best way to do so is with Windows Communication Foundation (WCF).
Then you could write code in your javascript to make calls to the webservice.
Why not just have it listen for commands on a socket?
http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.listen.aspx
Well this might be tricky because of the concurrency on the calls to the C# programm.
You could create a Webservice that is starting the C# program with the variables as arguments.
Or you might write the variables into a table and have the C# program poll for new entries to that table. This would overcome the concurrency issue. Combined with a WebService that writes the variables into the a table - this solution is working just fine.
You have two solutions here :
- Build a WCF service that you'll then use by doing SOAP calls
- Use a Socket to communicate
精彩评论