1.对窗体序列化
[Serializable]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public void show()
{
this.ShowDialog();
}
}
2.将窗体放于预定化接口中:
public class HelloServer : MarshalByRefObject
{
public HelloServer()
{
Console.WriteLine("HelloServer activated");
} public Form1 getForm()
{
return new Form1();
}
}
3.客户端将窗体Show出。
TcpChannel chan1 = new TcpChannel();
ChannelServices.RegisterChannel(chan1);
HelloServer obj1 = (HelloServer)Activator.GetObject(
typeof(RemotingSamples.HelloServer),
"tcp://192.168.0.102:8085/SayHello");
Form1 fr = obj1.getForm();
fr.show();问题:运行结果,客户端运行show,的方法后,窗体却在服务端打开。
请问各位,窗体如何在客户端打开。
[Serializable]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public void show()
{
this.ShowDialog();
}
}
2.将窗体放于预定化接口中:
public class HelloServer : MarshalByRefObject
{
public HelloServer()
{
Console.WriteLine("HelloServer activated");
} public Form1 getForm()
{
return new Form1();
}
}
3.客户端将窗体Show出。
TcpChannel chan1 = new TcpChannel();
ChannelServices.RegisterChannel(chan1);
HelloServer obj1 = (HelloServer)Activator.GetObject(
typeof(RemotingSamples.HelloServer),
"tcp://192.168.0.102:8085/SayHello");
Form1 fr = obj1.getForm();
fr.show();问题:运行结果,客户端运行show,的方法后,窗体却在服务端打开。
请问各位,窗体如何在客户端打开。
继承了MarshalByRefObject,使类可以通过引用封送的方式通过代理进行访问。
也就是说,客户端应用程序域通过代理可以垮应用程序域边界访问另外程序域(服务器中)所有导出类型。
如果想在客户端展示,用值封送的方式(Serializable),序列化->反序列化后在客户端显示。
2、Server端的:
public Form1 getForm()
{
return new Form1();
}
窗体实例是在Server端上,客户端调用
fr.show();
就是远程调用了前面Server段上new出来的窗口的Show方法,
Show方法的执行还是在Server上,因此Server上显示了窗口如果一定要Server上的类型的窗口要在客户端上打开(窗口类型经常会改变的情况?),那么就把窗口另外做一个Dll,
getform方法换成返回byte[],把Dll以字节的方式发送到客户端,通过AppDomain加载Dll
再通过反射,在客户端创建窗口实例,然后Show。