What's the most lightweight way to have two .net apps talk to each other?
We have a .net service with simple commands (play, pause, next track, for example). This is installed on users' workstation's with its own credentials (FooServiceUser, for example). If I want to give the users an app that can send the commands to the service, what would be the most lightweight way to do so? Remember I only want to send commands from a single workstation to a process running on that same workstation. The commands are very simple. Also the app needs to receive status from the service. ie paused, playing track 21.
Should be easy right? WCF looks complicated and overkill. Everyone on SO is saying .net remoting is bad. I don't want to ins开发者_StackOverflow中文版tall MSMQ. Every mention of sockets gets a negative score.
For a complete, easy to use solution I would recommend WCF. It supports a memory-channel protocol (ICP) for just this application.
Remains what you would call 'light-weight'. The hosting part of WCF can be accomplished in about 5 lines of code. All client-side code is generated. So do you really care about the number and size of the assemblies you have to use (already installed) or the amount of features you're going to ignore?
Just use WCF.
And it will let you easily scale out to sockets and inter-PC if the need ever arises.
I would have absolutely said Remoting is superseded and use WCF with named pipe binding but now that you are talking about lightweightness, I must say Remoting is lightweight and is not going anywhere since communication between two AppDomains are usually by remoting. So it is indeed a valid choice.
Having said that, considering the flexibility of WCF, I would still recommend - although it is heavy, chunky and way overcooked.
If the app is on the same machine as the Windows Service, you probably don't even have to worry about using remoting, web services, etc, since you can instantiate the ServiceController Class and use its ExecuteCommand method.
WCF is lightweight in terms of how may lines of code do i need to get my communication done. Its not very lightweight in terms of execution speed ans memory consumption. WCF is very simple to use. But its extensible architecture makes it sometimes a bit hard to find the right class.
Plain socket operation is not lightweight in terms of coding effort, but lightweight in terms of runtime operation. You have absolute full control over every bit, when channels are opened or closed and stuff like that.
精彩评论