Re: Problem accessing Remote Object properties

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Ken Kolda (ken.kolda_at_elliemae-nospamplease.com)
Date: 11/02/04


Date: Tue, 2 Nov 2004 08:45:05 -0800

You've registered your object as SingleCall. That means every single
propery/method call you make to your server will be run on a completely
seperate instance of your RemoteObject class. So, if your code looks like:

remoteObject.FileName = "myfile.xml"
string s = remoteObject.XmlFile;

those two lines are not running against the same object (even though the
cose looks like they are). SingleCall objects are meant be stateless, which
your object isn't as it holds the fileName and xml data between method
calls.

What you probably really want are client-activated objects (CAOs). CAOs are
created on demand by the client, so they are not shared by multiple clients.
For that you would use RegisterActivatedServiceType() on the server and, on
the client, use Activator.CreateInstance() (or
RegisterActivatedClientType()). For more info on CAOs and how to use them,
see

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconclientactivation.asp

Ken

"Jimski" <james.brock@ukonline.co.uk> wrote in message
news:1099412811.985996.243760@c13g2000cwb.googlegroups.com...
> Hi all,
>
> I am attempting to create a simple Winforms test app that consists of a
> Client and a Server. From the client I wish to create a remote object
> on the server, I then wish to pass this object a fileName that will
> then open the file and return the contents. (fairly simple I thought).
>
> I have created a separate class library to hold my remote object
> classes (this gets distributed with the client and server). It would
> appear that when I run the client and GetTheXml file I cannot access
> any of the RemoteObject properties, I believe the ProjectObject is
> being created, but when I then try and list the xmlFile string it
> returns absolutely nothing. I have also tried reading the
> ProjectObject.FileName after I have set it and this is also empty.
>
> I have included the code below. I cannot understand why my properties
> cannot be read from the proxy to the remote object?
>
> Can anybody offer any guidance please?
>
> Thanks in advance
>
> Jimski
>
>
>
> RemoteClass.dll
> ---------------
>
> public class ProjectObject : MarshalByRefObject
> {
> public ProjectObject()
> {
> xmlFile = "";
> }
>
> private string xmlFile;
> public string XmlFile
> {
> get
> {
> return xmlFile;
> }
> set
> {
> xmlFile = value;
> }
> }
>
> private string fileName;
> public string FileName
> {
> get
> {
> return fileName;
> }
> set
> {
> // opens the Xml file and populate a reader.
> fileName = value;
> XmlTextReader xmlReader = new XmlTextReader(fileName);
> while (xmlReader.Read())
> {
> if (xmlReader.NodeType == XmlNodeType.Element)
> {
> // sets the xmlFile string property
> xmlFile = xmlReader.ReadOuterXml();
> break;
> }
> }
> }
> }
> }
>
> Server.exe
> ----------
>
> public ServerForm()
> {
> InitializeComponent();
>
> channel = new TcpServerChannel(8086);
> ChannelServices.RegisterChannel(channel);
>
> RemotingConfiguration.RegisterWellKnownServiceType(typeof(ProjectObject),
> "ProjectObject", WellKnownObjectMode.SingleCall);
> //RemotingConfiguration.Configure("C:\\Devel\\James
> Brock\\Testing\\Server.config");
>
>
RemotingConfiguration.Configure("C:\\Development\\SimpleRemoting\\Server\\Se
rver.config");
> }
>
>
> Client.exe
> ----------
>
> private TcpClientChannel channel;
>
> public ClientFormForm()
> {
> InitializeComponent();
> channel = new TcpClientChannel();
> ChannelServices.RegisterChannel(channel);
> }
>
> private void btnGetXml_Click(object sender, System.EventArgs e)
> {
> if (openFileDialog.ShowDialog() == DialogResult.OK)
> {
> ProjectObject projObj = (ProjectObject)Activator.GetObject
> (typeof(ProjectObject), "tcp://servername:8086/ProjectObject");
> if (projObj != null)
> {
> projObj.FileName = openFileDialog.FileName;
> richXml.AppendText(projObj.XmlFile);
> }
> else
> {
> MessageBox.Show("Could not create the server side object
> Project Object");
> }
> }
> }
>



Relevant Pages

  • Each client gets the same port number
    ... This class creates a server socket that will ... For each new connection request from client ... */ private String calculate{String result = null; ...
    (comp.lang.java.help)
  • Re: pygame and socket.recv
    ... player, and for the communication, I am sending a pickle string across ... The client sends a dictionary to the server. ... time.sleep to keep the frame rate at 40 frames per second. ...
    (comp.lang.python)
  • Re: Applet Consideration
    ... > the client applet to connect to the server. ... everything is sent as String. ... >> I made it so the client has absolutely no knowledge that the db exists. ... Each thread must be initialized by a login. ...
    (comp.lang.java.databases)
  • Re: Applet Consideration
    ... the client applet to connect to the server. ... My computer(the server) is behind a router ... > i.e. boolean login(String domain, String user, String pass) ...
    (comp.lang.java.databases)
  • Re: What doesnt lend itself to OO?
    ... >> proxy and instructs the server to constuct the real object. ... rather than client code. ... If 'clock' is instantiated in the server, ... > for the server interface at the OOA level. ...
    (comp.object)