Re: Problem accessing Remote Object properties
From: Ken Kolda (ken.kolda_at_elliemae-nospamplease.com)
Date: 11/02/04
- Next message: Nathan: "RE: IPC in framework 2.0"
- Previous message: csliuyb: "RE: Remoting and XP SP2"
- In reply to: Jimski: "Problem accessing Remote Object properties"
- Next in thread: Jimski: "Re: Problem accessing Remote Object properties"
- Reply: Jimski: "Re: Problem accessing Remote Object properties"
- Messages sorted by: [ date ] [ thread ]
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");
> }
> }
> }
>
- Next message: Nathan: "RE: IPC in framework 2.0"
- Previous message: csliuyb: "RE: Remoting and XP SP2"
- In reply to: Jimski: "Problem accessing Remote Object properties"
- Next in thread: Jimski: "Re: Problem accessing Remote Object properties"
- Reply: Jimski: "Re: Problem accessing Remote Object properties"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|