By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,995 Members | 1,088 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,995 IT Pros & Developers. It's quick & easy.

Call Form from Library thru remoting

P: n/a
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.My Object),
"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);
}
}
Sep 22 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
sippyuconn,

Chances are here that the exception is occuring because when you make
the call to ShowDialog, it is on a thread other than the main UI thread.
When the call is remoted to the server form, the call comes in on another
thread, and you are trying to make a call to ShowDialog, which has to be
done on the main UI thread.

You can call Invoke, passing a delegate which will make the call to
ShowDialog.

I suspect this is just a test to learn remoting, but you should be aware
that this brings up another issue though. If you have multiple clients
calling this form, then it is possible that more than one dialog will be
shown at the same time.

Of course, another issue is that this requires the program to be running
on a logged in user session on the server side. This might be desirable, it
might not be, but it's something to be aware of.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"sippyuconn" <si********@newsgroup.nospamwrote in message
news:E7**********************************@microsof t.com...
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.My Object),
"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);
}
}
Sep 22 '07 #2

P: n/a
Hi Nicholas

Yes - I am just trying to get it running thru a test pgm

Do you have an example of using Invoke to pass a Delegate to make the call???

On using remoting - since I wanted to popup a UI I assume I wouldn't use
this as
a true Client/Server. I would assume this would run on the client but have the
remoted pgm on a shared drive - and the UI run in the pgm space of the
client pc. This way it could be pushed to all the clients by installing once
to the shared drive. We wouldn't want to have a UI exposed on a true
client/server - since the server would be un-attended. The older version of
this pgm was on c++ as a exe that was called cmdline with no gui(in the newer
version UI i integral to the pgm).
Clients would run on mapped drives and also true client/server installs
since no gui was involved. Since the UI is now in play that has limited my
options
a)remoting but only with mapped drive - no true client/server
b)somehow expose a COM interface to gui
c)do another cmd line interface to pgm

thanks
"Nicholas Paldino [.NET/C# MVP]" wrote:
sippyuconn,

Chances are here that the exception is occuring because when you make
the call to ShowDialog, it is on a thread other than the main UI thread.
When the call is remoted to the server form, the call comes in on another
thread, and you are trying to make a call to ShowDialog, which has to be
done on the main UI thread.

You can call Invoke, passing a delegate which will make the call to
ShowDialog.

I suspect this is just a test to learn remoting, but you should be aware
that this brings up another issue though. If you have multiple clients
calling this form, then it is possible that more than one dialog will be
shown at the same time.

Of course, another issue is that this requires the program to be running
on a logged in user session on the server side. This might be desirable, it
might not be, but it's something to be aware of.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"sippyuconn" <si********@newsgroup.nospamwrote in message
news:E7**********************************@microsof t.com...
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.My Object),
"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);
}
}

Sep 23 '07 #3

P: n/a
Hi,
Do you have an example of using Invoke to pass a Delegate to make the
call???

The following is a sampe:

delegate void MethodCallback();

public class MyObject : MarshalByRefObject
{
/// Return a hello message
public string HelloWorld()
{
if(this.InvokeRequired)
{
MethodCallback callback = new MethodCallback(HelloWorld);
string result = this.Invoke(callback).ToString();
return result;
}
else
{
Mathfrm frm = new Mathfrm();
frm.ShowDialog();
return (frm.Message);
}
}
}

Hope this helps.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 24 '07 #4

P: n/a
Hi Sippyuconn,

How about the problem now?

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Sep 26 '07 #5

P: n/a
Hi Linda - Thanks for the code but ....

I wasn't able to compile. The code where you added the Invoke and
InvokeRequired
is a not a windows form. Is there a way around that ????

Thanks
"Linda Liu [MSFT]" wrote:
Hi,
Do you have an example of using Invoke to pass a Delegate to make the
call???

The following is a sampe:

delegate void MethodCallback();

public class MyObject : MarshalByRefObject
{
/// Return a hello message
public string HelloWorld()
{
if(this.InvokeRequired)
{
MethodCallback callback = new MethodCallback(HelloWorld);
string result = this.Invoke(callback).ToString();
return result;
}
else
{
Mathfrm frm = new Mathfrm();
frm.ShowDialog();
return (frm.Message);
}
}
}

Hope this helps.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 28 '07 #6

P: n/a
Hi,

Thank you for your reply!
The code where you added the Invoke and InvokeRequired is a not a windows
form. Is there a way around that ????

You should add a reference to the assembly 'System.Windows.Forms' in the
class library project.

Hope this helps.
If you have any qustion, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Oct 4 '07 #7

P: n/a
Hello,

How about the problem now?

If the problem is still not solved, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Oct 8 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.