views:

226

answers:

1

I need to create a service. I know that you can do it with just a console application but it can also be done with ATL.. What are the benefits of the ATL Service vs a simple console application service? I understand that ATL is COM.. but what are the benefits of COM with the service.. thanks!

A: 

The service doesn't exactly benefit from COM, but rather the other way around.

By hosting your COM objects in a service, you get all the system features of services (startup before users log on, controlled policies watchdog, configuration of identity, etc.)

ATL gives you the opportunity to run your COM objects in a service context, as opposed to in-process (DLL) or regular out-of-process hosting. COM+ is another alternative for customized hosting.

If your service is just a background service, adding COM support could give you simple programmability, but otherwise I don't see any benefits.

So, I'm not sure that answers your question... The question feels backward :)

Kim Gräsman
I am wanting to write a service that has a listener socket. it will have several classes that are overlapped i/o. incoming connections will be attached to different io completion ports (depending on the "interrogation request"). I thought that doing an ATL service would give me extra benefits with the com. (attaching a debugger through com to find out what is going on and such). Is this approach a good one or should I just do a console application without atl? I also want to connect to a database with this service. hope this helps.
BabelFish
@BabelFish: We've been developing NT services without ATL for ages and never had problems debugging them - we just attach to the process and debug as usual.
sharptooth
Right, COM does not give you any additional debug capabilities.
Kim Gräsman
Thanks for the responses.. I was thinking of making a visual debugger (by debugger I was not meaning visual studio.. to clarify).. the service would feed info to the debugger and it would generate a 3d image of the structural model. It could report bottlenecks, processor usage etc.. the whole system could be managed from that debugger. I assume you are doing a console application then for the service? Any great boilerplate templates available for that? Including interaction with the service?
BabelFish
also.. it should be noted that my service will need a connection to database.. I will be using ADO..
BabelFish
You /could/ expose a COM API from your service to provide data for the fancy front-end, but you would still need to implement that front-end as a separate program, as services can't display UI. There are probably simpler IPC mechanisms you can use to provide the data, depending on how familiar you are with COM/DCOM.
Kim Gräsman
Your service can use ADO independent of whether you base it on ATL or not -- ATL is the easiest way to create a service that hosts COM classes. Any old program, service or not, ATL or console, can use ADO, as long as it calls CoInitialize on the thread that tries to create instances.
Kim Gräsman
@Kim Gräsman Yeah.. the front end would be a separate prog. what simpler IPC's did you have in mind? my other thought was using pipes.. seems like the best foundation to build off of might be an ATL service (no com interfaces to begin with) with the ability to add them later. thoughts?
BabelFish