473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Call Form from Library thru remoting

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
7 2152
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kurien Baker Fenn | last post by:
How to send data from an ASP form to a visual basic form? Please help
2
by: Jack Addington | last post by:
I am working on app that currently all resides on the same machine but plan to pull the database off and try to move all the datafunctionality to a remote machine. I have a data function that is...
5
by: Richard Kure | last post by:
Is it possible to get a webservice to call to a Windows Form? Both the webservice and the form are running at the same computer. I work in C#.NET in Visual Studio. I tried to make an eventin the...
2
by: Sharon | last post by:
I have a Form class that can be open by parent Form or by .NET Remoting command. When the parent Form opens the Form - All fine ! But when the .NET Remoting command is trying to Show the Form, the...
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
15
by: Alpha | last post by:
I was told that Unix API can only be called using C++, ATL and MFC. However, I was also told that C# can do that through Pinvoke to a DLL that interfaces with the Unix API. Can someone direct me...
5
by: Stephen Barrett | last post by:
I have read many threads related to async fire and forget type calls, but none have addressed my particular problem. I have a webpage that instantiates a BL object and makes a method call. The...
0
by: VishalSimon | last post by:
Remoting Error can not access property or method of proxy object on internet, works fine for LAN Hello, here is my some remoting code Code Snippet Remoted Class: namespace Server
4
by: roynevo | last post by:
Hi, I'm trying to deserialize an object on the context of a remoting call (RPC). The deserialization seem to work fine, however when I'm casting the result to the relevant class I get an...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.