Reputation: 45941
I'm developing a C# solution with .NET Framework 4.5.1.
I need to have a program (an object instance) running all the time waiting to receive commands. This program will have a state and depending on this state it will allow some commands or others.
For example, it will have an open and close command. If the state is not openned and the program receives the close command, it won't do anything.
I've thought to create a windows service or a ASP.NET MVC WebApi 2.2 app.
If I choose windows service, the program will be running always but I don't know how to communicate with it (maybe adding it a TCP/IP server).
If I use ASP.NET MVC WebApi 2.2 I can send the commands using POST or PUT messages, but I don't know if I can have an object instance running while the web service is up.
The program is a class that I have to instanced it. This instance will keep its state and a communication with a WCF service.
What do you recommend me?
Upvotes: 0
Views: 4191
Reputation: 37780
Options from which to choose are strange a little.
You can self-host Web API in windows service, and communicate with service using HTTP. Note, that Web API is about stateless, so, if you need to preserve the state, this should be a persistable data.
As to a way for communicate with windows service, using something other, than Web API - there are number of ways to do this. WCF with TCP/Named Pipes, pure Named Pipes (without WCF), sockets, memory mapped files. You just need to select most appropriate for your requirements.
Upvotes: 1