.net - Best way to send and receive messages between a Windows service and form application -
i'm attempting implement ipc, i'm doing different documentation i've seen.
i need asynchronously send, receive, , respond service , form application.
//service1.cs serverpipe = new namedpipeserverstream(@"testpipe", pipedirection.inout, 1, pipetransmissionmode.message, pipeoptions.asynchronous); //loginform.cs clientpipe = new namedpipeclientstream(@".", @"testpipe", pipedirection.inout pipeoptions.asynchronous);
i believe sets both sides.
to write 1 other:
//in service1.cs , login.cs private void pipewriter() { streamwriter write = null; write = new streamwriter(clientpipe); if (clientpipe.isconnected) { write.write(clientpipe); write.flush(); } }
... , read:
//in service1.cs , login.cs private void pipereader() { try { while (true) { using (streamreader sr = new streamreader(clientpipe)) { string message; while ((message = sr.readline()) != null) { //read , respond messages written stream } } } } catch (exception ex) { } }
am in right direct? there (better) way communicate between windows service , form application?
since you're in .net guess should wcf - windows communication foundation, define contracts (service contract, data contracts), publish service , use service without worrying protocol since can choose configuring server , client app.
you can take @ these links in information:
- http://www.codeproject.com/articles/29243/a-windows-communication-foundation-wcf-overview
- http://msdn.microsoft.com/en-us/library/ee958158.aspx
hope helps, cheers