Windows service talking to a Windows Application

G

Guest

We are trying to build a system where we have a Windows Service do some
manipulation of data, and then sending the data to a Windows App. I had
posted a question of how we should do this and was told remoting was the way
to go.

So I got a client and a server program up and going and from the client I
can call a routine in the server program. I can't figure out how to actually
send data to the client. At the moment the client calls a routine that
returns the time from the server (it's a stupid program but it proves it
works.) But what I want to do is send a dataset to the server and then have
the server do some processing on the dataset. I can figure out how to send
the dataset but what do I do at that point? I need to tell the server that it
has new data to process.

Anybody have any ideas on how to get this to work?

Thanks for your help.

Jeff.
 
N

Nicholas Paldino [.NET/C# MVP]

Jeff,

Well, what does your service do now then? I mean, it's running, and
that's great, but it has to do something. When your object that is being
remoted is hosted in your service gets a call through a method, that is your
opportunity to perform work. You are able to send back data in the form of
output parameters and return values.

Now, are you saying that you want to just call methods on the client
from the service? If that is the case, then you need an object on the
client which derives from MarshalByRefObject. You also need an interface
that is shared between the client and the service which exposes the methods
the service can call on the client.

When the client first connects to the service, you can pass the
implementation of this interface to the service, and the service can store a
reference to it. Because the object passed to the service derives from
MarshalByRefObject, the service will hold a proxy to the client, instead of
a serialized instance.

Hope this helps.
 
G

Guest

Nicholas,
Let me try again explaining what I want to do.

I have a service that is running that every once in a while goes out to a
database and does some calculations. I then have a Windows App that displays
the calculations. So I have my Windows service as a client of the windows
app. The service can call a method in the app (and that works fine) but I
can't figure out how to tell the win app that there's new data.

So here's a full outline of what I would like it to do:

Win App is up and going and dispays whatever.
Win Service starts up.
At some point the Win Service creates some new calculations.
Win Service wants to send some kind of notification (and results of the
calculations if possible) to the win app program.
Win App displays the new statistics.

I've got the win app program working. I've got the win service working. I
have the win service making a call to a routine in the win app program. But I
can't figure out what to do in the client so that it knows about the new
data. I can pass the new data in to a routine in the called routine but then
what do I do with it? How does the win app program know about the new data?

Thanks.

Jeff.

Nicholas Paldino said:
Jeff,

Well, what does your service do now then? I mean, it's running, and
that's great, but it has to do something. When your object that is being
remoted is hosted in your service gets a call through a method, that is your
opportunity to perform work. You are able to send back data in the form of
output parameters and return values.

Now, are you saying that you want to just call methods on the client
from the service? If that is the case, then you need an object on the
client which derives from MarshalByRefObject. You also need an interface
that is shared between the client and the service which exposes the methods
the service can call on the client.

When the client first connects to the service, you can pass the
implementation of this interface to the service, and the service can store a
reference to it. Because the object passed to the service derives from
MarshalByRefObject, the service will hold a proxy to the client, instead of
a serialized instance.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

WinDev said:
We are trying to build a system where we have a Windows Service do some
manipulation of data, and then sending the data to a Windows App. I had
posted a question of how we should do this and was told remoting was the
way
to go.

So I got a client and a server program up and going and from the client I
can call a routine in the server program. I can't figure out how to
actually
send data to the client. At the moment the client calls a routine that
returns the time from the server (it's a stupid program but it proves it
works.) But what I want to do is send a dataset to the server and then
have
the server do some processing on the dataset. I can figure out how to send
the dataset but what do I do at that point? I need to tell the server that
it
has new data to process.

Anybody have any ideas on how to get this to work?

Thanks for your help.

Jeff.
 
N

Nicholas Paldino [.NET/C# MVP]

WinDev,

That's why I recommended what I did with the interface. Going into more
detail, you would create an interface that exists outside of the client and
server assemblies, like this:

public interface ICallback
{
void DataUpdated(DataSet ds);
}

I'm using a data set here, but you can use anything.

Then, in the client, you would create a class that derives from
MarshalByRefObject which implements this interface.

On the server, you would expos a method which take a parameter of this
interface type.

Then, when your client starts up, you will call the method in the server
which takes an instance of the ICallback interface (or whatever you name it)
and then pass the instance of your object on the client side. The server
will get a proxy to the client, which it can then call into to notify it of
the "update".

Of course, the client on the object can also expose methods and whatnot,
or have a reference to the UI, whatever you need to perform your update of
the data.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

WinDev said:
Nicholas,
Let me try again explaining what I want to do.

I have a service that is running that every once in a while goes out to a
database and does some calculations. I then have a Windows App that
displays
the calculations. So I have my Windows service as a client of the windows
app. The service can call a method in the app (and that works fine) but I
can't figure out how to tell the win app that there's new data.

So here's a full outline of what I would like it to do:

Win App is up and going and dispays whatever.
Win Service starts up.
At some point the Win Service creates some new calculations.
Win Service wants to send some kind of notification (and results of the
calculations if possible) to the win app program.
Win App displays the new statistics.

I've got the win app program working. I've got the win service working. I
have the win service making a call to a routine in the win app program.
But I
can't figure out what to do in the client so that it knows about the new
data. I can pass the new data in to a routine in the called routine but
then
what do I do with it? How does the win app program know about the new
data?

Thanks.

Jeff.

Nicholas Paldino said:
Jeff,

Well, what does your service do now then? I mean, it's running, and
that's great, but it has to do something. When your object that is being
remoted is hosted in your service gets a call through a method, that is
your
opportunity to perform work. You are able to send back data in the form
of
output parameters and return values.

Now, are you saying that you want to just call methods on the client
from the service? If that is the case, then you need an object on the
client which derives from MarshalByRefObject. You also need an interface
that is shared between the client and the service which exposes the
methods
the service can call on the client.

When the client first connects to the service, you can pass the
implementation of this interface to the service, and the service can
store a
reference to it. Because the object passed to the service derives from
MarshalByRefObject, the service will hold a proxy to the client, instead
of
a serialized instance.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

WinDev said:
We are trying to build a system where we have a Windows Service do some
manipulation of data, and then sending the data to a Windows App. I had
posted a question of how we should do this and was told remoting was
the
way
to go.

So I got a client and a server program up and going and from the client
I
can call a routine in the server program. I can't figure out how to
actually
send data to the client. At the moment the client calls a routine that
returns the time from the server (it's a stupid program but it proves
it
works.) But what I want to do is send a dataset to the server and then
have
the server do some processing on the dataset. I can figure out how to
send
the dataset but what do I do at that point? I need to tell the server
that
it
has new data to process.

Anybody have any ideas on how to get this to work?

Thanks for your help.

Jeff.
 
J

John Murray

I am assuming, from your description, that your workflow is something like:

1) Client gets some data from a source other than the server
2) Client hands the data to the server, and the server takes a lot of
time to manipulate it, but the client doesnt want to block on this
operation.
3) On completion of the manipulation, the server hands the data back to
the client.


If that is true, an easy way to do this would be to have the server hand
back a key to the client in step 2, and then have the client poll for
completion of the work in a background thread. Depending on what you
needed to do, you might also consider just doing the post in 2
asynchronously.
 

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