Windows Services Communication

I have to implement a solution using Windows Services however I have no experience in doing so. Basically I have a "master" windows service that calls an "agent" windows service on different servers to perform various tasks.  I have figured out most of it, however I need for the "agent" windows service to send a message back to the "master" when it has finished all its tasks, so that the "master" can then call the next "agent". Can anyone give me an idea on how to go about doing this? Thanks.
cute6481Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sachiekCommented:
You can use delegates kind of solutions.

Invoke all the agents as seperate functions from your master service.

or

Invoke each agent in one seperate thread. So it is autonomy. Once those task completed you will get notified automatically.

Still not covienced. Pls reply.


Sachi
0
KelmenCommented:
As you mentioned you figured most of it except the agent callback the master part.

Sounds to me its an asynch process.

How about using socket for the communication part?

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemNetSockets.asp?frame=true

The TcpClient and TcpListener there may give some idea to kickoff.

HTH
0
cute6481Author Commented:
Thank you for your replies guys.

Is it possible to use a custom command for what i want to do?  I have been told that I can execute a cutom command and get a reply back to my calling service (which im thinking i might just change to a console app as it is not good practice to have a service controlling a service??). Any feedback is appreciated. Documentation on the custom command seems to be sparse...
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

sachiekCommented:
Actually I had something similar requirement earlier.

i.e. A Master agent will call each sub agent for certain tasks to be completed. Doing those sub tasks sequentially.

I tried it with remoting. It means sub task will be invoked from master agent.

but then finally i changed the design to one single windows service.

You can see an example in windows itself. When you try to stop IIS from windows service window it will stop other three services automatically. i.e Index service, SMTP (is installed) then one other service. While starting also it does in that same way.
Surely your requirement can be done with remoting in C#.  Let me know if you want a sample which i got relatively similar to your requirement.


Sachi

 
 
0
cute6481Author Commented:
Thanks Sachi.

I have been told to use WMI to complete this project. I think I have figured out how to go about it.. I have a console application which calls custom commands on windows services to perform various tasks (using ServiceController.ExecuteCommand.. The only issue I have now is how my console app is going to know that the custom command has finished either successfully or otherwise - does anyone know of a way to do this???
0
sachiekCommented:
Oh ok. That is intresting.

I managed to find an article from microsoft regarding this MMC which is inturn called WMI also.

http://msdn.microsoft.com/vstudio/default.aspx?pull=/library/en-us/dnhcvs04/html/vs04d6a.asp
Check this out.

Ya, It is one good thing to learn. Executecommand can be used.


I will post further soon.

Sachi
0
sachiekCommented:
Hmm.. there is also ready avilable MMC library.

http://sourceforge.net/projects/mmclibrary/

Check this above url to get it.


Sachi
0
sachiekCommented:
Further below are my findings.


*****
 Server has a number of Windows Services (I see at least 3) that run,
plus it has a UI program that runs, the services are listed under Services
in the "Control Panel - Administrative Tools"

The UI program (for SQL Server) is called "Service Manager" is under
Programs - Startup.

A service accept a "command" (from its UI) is to do something is to override the ServiceBase.OnCustomCommand method and have it call the same procedure your Timer.Elapsed event handler calls.

Then you can use ServiceController.ExecuteCommand to invoke this custom
command.

Note: Probably define an Enum of CustomCommands that my service
supported so its easier to keep track of them. A custom command for
OnCustomCommand is an integer between 128 & 256, which also means  you can
have multiple custom commands defined.

Remember that ServiceController can control services on your local machine
as well as services on remote machines. Note you may need to configure the
various machines to allow remote control of services.


Custom commands with a service are discussed in Matthew MacDonalds book "Microsoft Visual Basic .NET Programmer's Cookbook" from MS Press
*****

Sachi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cute6481Author Commented:
Thanks heaps for your help!! Looking into it all now....
0
cute6481Author Commented:
Great Information - thanks Sachi.

I have managed to just about complete it all, however I am having issues trying to Execute my custom command... I am using the code ServiceController.ExecuteCommand(130) however I get an error telling me that I "cannot control Service 1 on ".". All the reading i have done suggests this error occurs due to an invalid command number (so this is not the problem as i am using 130) or from security setting but i am just running it on my local machine so i don't believe this is the problem either. Any ideas??
0
sachiekCommented:
Is there any error number?


Sachi
0
sachiekCommented:
Can you double check your custom value. Is it surely 130?

I guess this error is thrown because of executecommand received number less than 128.


Sachi

0
cute6481Author Commented:
Nope. My application hangs for about 30 seconds and then the error is finally caught in my catch, saying "Cannot Control Service on computer '.'".
0
cute6481Author Commented:
My Custom value is definitley 130... i have even tried it with other values (200, 150) and still same result.
0
sachiekCommented:
You should not impersonate the user. Try to use system local account.

Sachi
0
cute6481Author Commented:
I was using the local system account.  The problem was that I was running my test application in the same solution that I created the windows service in which was causing some kind of conflict.  Is all fixed now. Thanks for your help Sachi.
0
sachiekCommented:
Can I have this sample application :) ?

Sachi
0
cute6481Author Commented:
Yeah no problem... as soon as i finish it! Having an issue with logging to an event log on a remote computer - have posted a seperate question about this. As soon as its done you can have a copy.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.