How to connect to a service?

V

Vincent Finn

Hi,

I have a Windows service written in C#
I want to access it from a C# app (or a C++ app for that matter)

How can I do this?

I tried referencing it but it fails telling me the it's not a valid
Assembly or ActiveX (i.e. not a dll)
I can't create an interop dll because that is disabled for services

I can use the Server Browser to start and stop it, but i want to store
and access data in the service and I can't see how

Vin
 
V

Vincent Finn

Hi Vincent, take a look at the ServiceController class.

That only allows me to do standard service actions like starting and
stopping

It doesn't give me access to user defined functions.

eg.
The service is monitoring some external systems,
it queries them to see if they are alive and can be used to send
commands to them

I want to have a control app that connects to the service and sends
commands to those systems.
So I want a function in my service called
WriteToScreenServer("ServerName", "Message")

In Com this would be a simple matter of adding a Com interface and
then using it as normal.

I can't see the .Net equivalent

Vin
 
E

Elp

I want to have a control app that connects to the service and sends
commands to those systems.
So I want a function in my service called
WriteToScreenServer("ServerName", "Message")

In Com this would be a simple matter of adding a Com interface and
then using it as normal.

I can't see the .Net equivalent

The .NET equivalent would be .NET Remoting. Expose a .NET Remoting object
from within your windows service and have your client application connect
to it. The client app will then be able to call any of the methods of the
..NET Remoting object. In addition, your windows service will be able to
send events to your client application through this object.

This is of course not the only solution for your problem. You could also
use raw socket communication, pipes... But in your case, it seems that .NET
Remoting would be the easiest solution.
 
V

Vincent Finn

The .NET equivalent would be .NET Remoting. Expose a .NET Remoting object
from within your windows service and have your client application connect
to it. The client app will then be able to call any of the methods of the
.NET Remoting object. In addition, your windows service will be able to
send events to your client application through this object.

This is of course not the only solution for your problem. You could also
use raw socket communication, pipes... But in your case, it seems that .NET
Remoting would be the easiest solution.

Thanks, I'll have a read up on that

Vin
 

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