G
Guest
Hi
I am trying to see if I can call a Library remotely. The library contains a
Form
that I want to display then pass back some data to user that called this
form remotely.
I have it working some-what.
I am able to call form remotely and return data to client but somewhere
after closing remote form and returning data - I get a Windows exception -
not sure where though
If anyone can see anything it would be greatly appreciated or better ways of
doing this ???
Thanks
Server form
=====
public Form1()
{
InitializeComponent();
// Create an instance of a channel
TcpChannel channel = new TcpChannel(8080);
ChannelServices.RegisterChannel(channel);
// Register as an available service with the name HelloWorld
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyObject),
"HelloWorld", WellKnownObjectMode.SingleCall);
}
Client form
====
MyObject obj;
public Form1()
{
InitializeComponent();
// Create a channel for communicating with the remote object
// Notice no port is specified on the client
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
// Create an instance of the remote object
obj = (MyObject)Activator.GetObject(typeof(MyRemoting.MyObject),
"tcp://localhost:8080/HelloWorld");
}
private void simpleButton1_Click(object sender, EventArgs e)
{
// Use the object
if( obj.Equals(null) )
{
this.Text = "Error: unable to locate server";
}
else
{
this.Text = obj.HelloWorld();
}
}
Library - I have public property on Form that captures text in textbox
====
public class MyObject : MarshalByRefObject
{
public MyObject()
{
}
/// Return a hello message
public string HelloWorld()
{
//return "Hello World!";
Mathfrm frm = new Mathfrm();
frm.ShowDialog();
return (frm.Message);
}
}
I am trying to see if I can call a Library remotely. The library contains a
Form
that I want to display then pass back some data to user that called this
form remotely.
I have it working some-what.
I am able to call form remotely and return data to client but somewhere
after closing remote form and returning data - I get a Windows exception -
not sure where though
If anyone can see anything it would be greatly appreciated or better ways of
doing this ???
Thanks
Server form
=====
public Form1()
{
InitializeComponent();
// Create an instance of a channel
TcpChannel channel = new TcpChannel(8080);
ChannelServices.RegisterChannel(channel);
// Register as an available service with the name HelloWorld
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyObject),
"HelloWorld", WellKnownObjectMode.SingleCall);
}
Client form
====
MyObject obj;
public Form1()
{
InitializeComponent();
// Create a channel for communicating with the remote object
// Notice no port is specified on the client
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
// Create an instance of the remote object
obj = (MyObject)Activator.GetObject(typeof(MyRemoting.MyObject),
"tcp://localhost:8080/HelloWorld");
}
private void simpleButton1_Click(object sender, EventArgs e)
{
// Use the object
if( obj.Equals(null) )
{
this.Text = "Error: unable to locate server";
}
else
{
this.Text = obj.HelloWorld();
}
}
Library - I have public property on Form that captures text in textbox
====
public class MyObject : MarshalByRefObject
{
public MyObject()
{
}
/// Return a hello message
public string HelloWorld()
{
//return "Hello World!";
Mathfrm frm = new Mathfrm();
frm.ShowDialog();
return (frm.Message);
}
}