HighTechTalks DotNet Forums  

Exposed Object vs Remoting server

Dotnet Framework (Remoting) microsoft.public.dotnet.framework.remoting


Discuss Exposed Object vs Remoting server in the Dotnet Framework (Remoting) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
news.microsoft.com
 
Posts: n/a

Default Exposed Object vs Remoting server - 12-16-2004 , 11:26 AM






Hello!
I have a remoting server which exposes a Singleton object to a client.
The client can call methods on the object without any problem.

Now, I'm trying to let the client modify the exposed object.
My question is: How would the server be able to load the exposed object
an retrieve the value set by the client? I'm asking because there is no
mention of the currently exposed instance of the class in the server code.

Or how do I expose a named instance of an abject to my clients? (having
a named instance would probably solve my problem)

Thanks

Reply With Quote
  #2  
Old   
Ken Kolda
 
Posts: n/a

Default Re: Exposed Object vs Remoting server - 12-16-2004 , 01:27 PM






Allow the server to access the same object which is remoted to the clients
is a frequently occurring problem in remoting. Luckily, the answer is pretty
simple. Currently, you've probably registered your remoting object using
RemotingConfiguration.RegisterWellKnownServerObjec t(). The problem is that
this method exposes the object anonymously, i.e. the server doesn't have a
reference to this instance.

To fix this, you do two things:

1) Declare and instantiate a named instance of your remote object.
2) Get rid of your call to RegisterWellKnownServerObject() and instead call
RemotingServices.Marshal() on your named object. This will expose the object
so it can accept client requests.

Hope that helps -
Ken


"news.microsoft.com" <xxx (AT) xxx (DOT) com> wrote

Quote:
Hello!
I have a remoting server which exposes a Singleton object to a client.
The client can call methods on the object without any problem.

Now, I'm trying to let the client modify the exposed object.
My question is: How would the server be able to load the exposed object
an retrieve the value set by the client? I'm asking because there is no
mention of the currently exposed instance of the class in the server code.

Or how do I expose a named instance of an abject to my clients? (having
a named instance would probably solve my problem)

Thanks



Reply With Quote
  #3  
Old   
Ken Kolda
 
Posts: n/a

Default Re: Exposed Object vs Remoting server - 12-16-2004 , 01:34 PM



You're seeing 2 and 4 because you've registered the Clock type as SingleCall
instead of Singleton. When a type is SingleCall, ever property/method you
access causes a new instance of the object to be created to service the
request. So, in your client code where you have:

Console.WriteLine ("Clock " +
clock.Number.ToString() + " " +
clock.GetCurrentTime ());

the "clock" instance used to access the "Number" property is actually
different from the instance used to call the GetCurrentTime() method, even
though from the client's side these appear to be the same instance.

What you are likely trying to achieve is that you get a new instance in each
iteration of the loop. In that case, you need to use client-activated
object. To do this, use RegisterActivatedServerType() on the server side and
RegisterActivatedClientType() on the client side. Then your code will behave
as you expect.

Ken


"Rob Richardson" <notreally (AT) n2net (DOT) net> wrote

Quote:
Greetings!

You asked exactly the same question I asked two threads below. I also
posed
the question to a co-worker who is more familiar with the possibilities of
the .Net framework than I am. He proposed a method based on a separate
class that can send a copy of the remoted object back to the server. I
don't understand it, but it works. I am attaching a zip file containing a
sample based on the Clock1 example in chapter 15 of "Programming Microsoft
.Net" by Jeff Prosise. Just change your IP address and port numbers as
desired, and things should work.

If somebody would kindly explain why twice as many clock objects are
created
as I need, I'd greatly appreciate it. The client creates two of them,
numbered 1 and 3. I don't understand why clocks 2 and 4 are being
created.

Rob






Reply With Quote
  #4  
Old   
Rob Richardson
 
Posts: n/a

Default Re: Exposed Object vs Remoting server - 12-16-2004 , 01:53 PM



Ken,

Thanks for your reply. I am a newbie in this area, and do not know about
named objects. I haven't found a clear sample on the Web. Could you point
me to a sample of this technique?

Thanks again!

Rob



Reply With Quote
  #5  
Old   
Rob Richardson
 
Posts: n/a

Default Re: Exposed Object vs Remoting server - 12-16-2004 , 02:09 PM



Thanks again, Ken. Now that somebody who knows what he's doing explains it,
it makes sense!

Rob



Reply With Quote
  #6  
Old   
Rob Richardson
 
Posts: n/a

Default Re: Exposed Object vs Remoting server - 12-16-2004 , 03:08 PM



Ken,

I tried using RemotingServices.Marshal() as you suggested. It worked!

In the server, I replaced:
RemotingConfiguration.RegisterWellKnownServiceType (typeof (Clock), "Clock",
WellKnownObjectMode.SingleCall);
with:
Clock serverClock = new Clock();
serverClock.Number = 99;
ObjRef serverClockRef = RemotingServices.Marshal(serverClock,
"ServerClockURI");

In the client, I replaced:
RemotingConfiguration.RegisterWellKnownClientType (typeof (Clock),
"tcp://localhost:1234/Clock");
with:
RemotingConfiguration.RegisterWellKnownClientType (typeof (Clock),
"tcp://192.168.1.29:1234/ServerClockURI");

The client application happily reported that it was using clock number 99.

Next question: For my application as it is currently designed, this will
suffice, since there will never be more than a single client communicating
with a server. But what happens when we decide that a single server
application will manage an unknown number of printers? In that case, I
would want my objects to be client-activated, but I still want the server to
know what objects it created. How do I do that?

Thanks again!

Rob



Reply With Quote
  #7  
Old   
Ken Kolda
 
Posts: n/a

Default Re: Exposed Object vs Remoting server - 12-16-2004 , 03:50 PM



In this case, you probably want to go with a factory model. In this model,
you create a singleton SAO which serves up your CAOs. By doing this you're
able to keep a hold of references to the same CAOs used by the clients. For
a good explanation of implementing a factory model in remoting, check out:

http://www.glacialcomponents.com/ArticleDetail/CAOGuide.aspx

Ken


"Rob Richardson" <notreally (AT) n2net (DOT) net> wrote

Quote:
Ken,

I tried using RemotingServices.Marshal() as you suggested. It worked!

In the server, I replaced:
RemotingConfiguration.RegisterWellKnownServiceType (typeof (Clock),
"Clock",
WellKnownObjectMode.SingleCall);
with:
Clock serverClock = new Clock();
serverClock.Number = 99;
ObjRef serverClockRef = RemotingServices.Marshal(serverClock,
"ServerClockURI");

In the client, I replaced:
RemotingConfiguration.RegisterWellKnownClientType (typeof (Clock),
"tcp://localhost:1234/Clock");
with:
RemotingConfiguration.RegisterWellKnownClientType (typeof (Clock),
"tcp://192.168.1.29:1234/ServerClockURI");

The client application happily reported that it was using clock number 99.

Next question: For my application as it is currently designed, this will
suffice, since there will never be more than a single client communicating
with a server. But what happens when we decide that a single server
application will manage an unknown number of printers? In that case, I
would want my objects to be client-activated, but I still want the server
to
know what objects it created. How do I do that?

Thanks again!

Rob





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.