Service Remoting Help!

A

Annette Miller

Hi All,

Just after some help here. I have an app running as a service and I'd like
to be able to communicate with it using remoting.

At the moment I'm using sockets and parsing the data. Remoting seems like a
better option but after a lot of googling and help reading I can't quite
work out how to be able to pass a class between to the service and client -
I want the service to send the class, say, status filled with information,
and have the client be able to call methods and classes to the server. Does
that make sense?

Can anyone point me in a good example of this?

Cheers, and thanks in advance..
 
L

Lars Behrmann

Hi,

to use a class via remoting you simply pu into an own dll.
This .dll will be the well known type for the client and the
server app. Here a little example snippet (Where Notifier
is my dll that will be used via remoting.

Server:
public void Listen()
{
HttpChannel hc = new HttpChannel(8989);
ChannelServices.RegisterChannel(hc);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Notifier),
"Notifier",
WellKnownObjectMode.SingleCall);
}

Client:
HttpChannel hc = new HttpChannel();
ChannelServices.RegisterChannel(hc);

RemotingConfiguration.RegisterWellKnownClientType(typeof(Notifier),
"http://localhost:8989/Notifier");
Notifier n = new Notifier();
//all operations on n will be executed
//on the server
Cnsole.WriteLine(n.Add(4, 8));

Notice: Make shure that both client and server reference exactly
the same .dll version. To avoid trouble you should set the assembly
version to a fixed value.

Cheers
Lars Behrmann

_________________
Nothing is impossible. UML is the key for all your problems.
AODL - Make your .net apps OpenOffice ready
http://aodl.sourceforge.net/
 
A

Annette Miller

Hi Lars,
Thanks for your reply. I had worked that much out but I don't see what the
difference between calling a class method on a remoting service or locally -
if it's self contained in a DLL. What I want to do is be able to populate a
class with my services data structures and transport them to the client. So
for example, the service might load and instantiate a shared class (from a
class library) and populate it with information and have the client be able
to retrieve that information.

I.e. Service:
Create class X and fill field Y with the value "Test Value"

Client:
Connect to service and get the previous instantiated class X and be able to
read that field Y is "Test Value"

Does that make sense?
Cheers.
 
L

Lars Behrmann

Hi Annette,

of course that make sense. Let's say for example.
Your shared class has a public method string GetField()
and if you call that method within your client the server
will get the value e.g. from a database which run on the
server. So you will recieve data from a database that
don't run on the client. What ever the shared class will
do it's executet on the serverside. I think it will be helpfull
if you run the client and server app on different machines
and put some code into the shared .dll that only can be
executet on the server e.g. an database query.

Cheers
Lars Behrmann

_________________
Nothing is impossible. UML is the key for all your problems.
AODL - Make your .net apps OpenOffice ready
http://aodl.sourceforge.net/
 
A

Annette Miller

Hi Lars,

I understand that, but what I want to do is actually fill the class with
service-specific information, for example what my Windows Service is doing
at the time the client requests the class.

Cheers.
 
M

Metallikanz!

What you need is a ServerActivated, MarshalByRef object which implements a shared interface deployed at both the client and the server. Using RemotingServices this interface can be used to acquire the remote reference and invoke methods and pass information the way you want it.

There's a very nice book on this subject titled, 'Advanced .NET Remoting' co-authored by Ingo Rammer.
 
A

Adam Cooper

Hi there,

..NET remoting uses two types of classes: MarshalByRef and Serializable.
As you might be able to guess from the names MarshalByRef is actually
a remote reference and all method calls are remote calls. A
Serializable class is a class that is passed entirely across the wire.
Ie. all fields are passed across and reconstructed on the other side.

Therefore, in you're type of application where you want to send a data
class across, you will need at least one of each type. The exposed
interface to the client will be the MarshalByRef object and the class
it returns to the client willb e the Serializable class.

When creating these classes, they both should be in a seperate library
that is found both on the server and the client. On the server and
client side you will use configuration files or API to configure these
classes as remote classes.

Cheers,
Adam Cooper
 

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