vb.NET Front-End/Windows Service Communication...

B

Brian Patrick

I have an application model which will consist of a front-end
configuration application, which needs to control the state of a
back-end vb.net windows service (which is the component that does all
the work). Think of this in the same manner as say microsoft management
console and the w3svc (inetinfo) service.

What should the standard communication protocol be between the
configuration app and the service in this model?

For example, If I'm using the configuration app, and I click a button to
tell the service to do some action, what means of communication should I
use. Obviously, with .net, COM is not the way to go. Writing an XML
file, and having the service poll for changes in the xml file seems
hokey. So, I guess I'm looking for the proper way to handle this.

Any info you can provide would be appreciated...

Thanks,
Brian
 
J

Jay B. Harlow [MVP - Outlook]

Brian,
The easiest way to have a service accept a "command" 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 I would 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.

An alternative, more flexible method, which also entails more work, is to
enable your service for .NET Remoting. You could either make it a .NET
Remoting Server, in which case you call a method to have it perform some
action, or a .NET Remoting Client, and possible handle an "update data
event" on your server remoting object that says to update data...

Both of the custom commands & remoting with a service are discussed in
Matthew MacDonalds book "Microsoft Visual Basic .NET Programmer's Cookbook"
from MS Press.

Hope this helps
Jay
 
G

Guest

Jay - thanks for the reply. I have a question for you...

If using your ExecuteCommand idea, how would I pass parameters to the
service from the front-end app? It sound's like you mean I could just tell
the service to run one of a possible 128 commands, but not be able to pass
data along. Let me know if I'm incorrect...

Thanks,
Brian
 
J

Jay B. Harlow [MVP - Outlook]

Brian,
You are correct ExecuteCommand only allows you to run one of a possible 128
commands, no parameters.

If you need parameters, I would recommend the .NET Remoting solution.

As an alternative, depending on the nature of the parameters, I would
consider writing them to the Service's app.config file, then stopping &
restarting the service. If your service only has a single service in it,
stopping it causes it to be unloaded from memory, restarting it should then
cause it to re-read its app.config. Of course if you service reads its
config from the registry or a different file, then you may not need to stop
& restart it.

Hope this helps
Jay
 
J

Jeff Johnson [MVP:VB]

I have an application model which will consist of a front-end
configuration application, which needs to control the state of a
back-end vb.net windows service (which is the component that does all
the work). Think of this in the same manner as say microsoft management
console and the w3svc (inetinfo) service.

What should the standard communication protocol be between the
configuration app and the service in this model?

I've been planning on doing this myself and I was told that Remoting is the
way to go.
 
G

Guest

Thanks guys - I'll have to look into .net remoting then. Do you know of any
*working* sample projects that are downloadble from the web?

Thanks,
Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top