views:

112

answers:

2

Let's say I have two windows services running. One service is 'Polling' - it polls the database for print jobs. As soon as the new print job is found, another service - 'Printing' - must send the job to the printer.

(Why I can not do it with one service is a separate issue, let's just say there is a reason for that).

The simple solution idea that I have is for the 'Polling' service to create and save the print job to a file somewhere, and for the 'Printing' service to monitor that location, read the file and execute the print job.

Is there a better way to do it - is it possible to somehow invoke the 'Printing' functionality from the 'Polling' service directly?

Development tool is .NET 3.5/C# if that matters.

+3  A: 

Yes, you can use WCF to allow the services to talk to one another. A NetNamedPipes binding is a good choice for local, on-the-same-box communications.

Jerry Bullard
I agree, NetNamedPipeBinding is the way to go for easy inter-process communication when you have WCF at your disposal.
bobbymcr
Accepting because it looks simple enough to understand and I already have a small working sample running.
Evgeny
+3  A: 

It's a standard IPC problem and there are as many solutions as there are ways to skin a cat: sockets, pipe, files, mapped memory etc.

For your specific example it sounds like a message queue might be a good solution. The first service could write the job to the queue and the second service could read it when convenient. That would cope with things like the printer being busy, offline etc.

sipwiz
Yes, absolutely right - many ways to do it. The use of the FileSystemWatcher class (http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx) he described would act just like a queue. Another option, since the services are on the same box, is an OS Mutex for IPC. Hi perf though not big on data transfer. Coupled with a file drop it might be just the thing. Which option to choose is a matter of skills you have, skills you want to bbuild, future evolution of the system, and so on. Perf won't be an issue.
Cheeso