Convert forms app to a service...

J

JamesB

Can anyone give me some "high level" pointers on converting an app to a
service?

Most of my "logic" is in a seperate class already which will help, but how
do I go about actually getting the two bits to talk?

Assuming I can take all the guts out and build a service, what's the usual
method for a forms app to talk back to that service? Basically my service
would be doing some background processing, and the forms app would show the
status of this, and allow configuration etc. However, the service should
still continue it's working even if the forms app is not running.

I've created services before, just not ones that have a related "front
end"...

James
 
N

Nicholas Paldino [.NET/C# MVP]

James,

To communicate between a UI app and the service, you will most likely
want to use Remoting or WCF in order to make calls to objects you expose
from the service. The messages or actions you send to the service would be
in the form of method calls.
 
B

Ben Voigt [C++ MVP]

JamesB said:
Can anyone give me some "high level" pointers on converting an app to a
service?

Most of my "logic" is in a seperate class already which will help, but how
do I go about actually getting the two bits to talk?

Assuming I can take all the guts out and build a service, what's the usual
method for a forms app to talk back to that service? Basically my service

If there's any chance that the UI might ever control the service on a
different computer, you might want to use TCP/IP sockets. That gives you
immense flexibility and is a standard. Named pipes are another good option,
if both computers will always run Windows (this is a C# group, so I guess
that's a pretty good assumption) and will let you take advantage of Windows
security by defining an access control list which will be checked against
the user's login.
 
A

Arnshea

Can anyone give me some "high level" pointers on converting an app to a
service?

Most of my "logic" is in a seperate class already which will help, but how
do I go about actually getting the two bits to talk?

Assuming I can take all the guts out and build a service, what's the usual
method for a forms app to talk back to that service? Basically my service
would be doing some background processing, and the forms app would show the
status of this, and allow configuration etc. However, the service should
still continue it's working even if the forms app is not running.

I've created services before, just not ones that have a related "front
end"...

James

I'd probably go with a remoting based solution. It may not be trivial
to convert the functionality from a form to a remotely accessible app;
you may have to deal with synchronizing access from multiple clients,
have to handle any leakage that might have been masked by a form that
started and stopped frequently, etc...

If you go with remoting I'd recommend going with a server-activated
object that's single-call (if applicable) or singleton. Single-call
may be a quick and dirty way to get the transition going but usually,
if you're going to embed the object in a service, you'll need to make
it a singleton.

See the .net framework documentation (programming with the .net
framework - accessing objects in other application domains) for an
excellent overview of remoting.
 
J

JamesB

Arnshea said:
I'd probably go with a remoting based solution. It may not be trivial
to convert the functionality from a form to a remotely accessible app;
you may have to deal with synchronizing access from multiple clients,
have to handle any leakage that might have been masked by a form that
started and stopped frequently, etc...

If you go with remoting I'd recommend going with a server-activated
object that's single-call (if applicable) or singleton. Single-call
may be a quick and dirty way to get the transition going but usually,
if you're going to embed the object in a service, you'll need to make
it a singleton.

See the .net framework documentation (programming with the .net
framework - accessing objects in other application domains) for an
excellent overview of remoting.

Thanks for all the replies so far - given me a couple of things to think
about and some pointers to the sort of documentation to be looking at.
Initially I was thinking that the service would only be controlled
intermittently by the form on the machine the service was running on,
however your replies have led me to think that accessing it from another
computer may actually be a bonus (thinking how *I* might want to run it) so
even more to think about there!

James
 

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