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