[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Problem accessing Remote Object properties

Jimski

11/2/2004 4:27:00 PM

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\\Server.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");
}
}
}

3 Answers

Sam Santiago

11/2/2004 4:42:00 PM

0

Try defining a public method to perform the reading and returning of the XML
file. Fields and accessor methods are not available remotely. Check out
this link on the limitations of remoting:

Scope of Publication
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconscopeofpubli...

Here's an excerpt:

"Different remoting systems have different ways of deciding which members
and what type of members can be used remotely. .NET remoting exposes objects
to other application domains as though they were local, with the following
exceptions:

a.. Instance fields and accessors.
For instance fields and accessor methods, the system inserts a check at
run time to determine whether the object is a proxy. If it is not a proxy,
field access is direct. Otherwise, the proxy provides accessors to the
caller."

Thanks,


Sam


--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTe...
_______________________________
"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");
> }
> }
> }
>


Ken Kolda

11/2/2004 4:45:00 PM

0

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/cpconclientacti...

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");
> }
> }
> }
>


Jimski

11/2/2004 5:18:00 PM

0

Thanks very much both of you. I have done it Ken's way using CAO's and
I have a basic working app. Now to build on that.

Jimski