日期:2014-05-18  浏览次数:20775 次

Remoting 将窗体序列化后,在客户show出来。
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,的方法后,窗体却在服务端打开。
请问各位,窗体如何在客户端打开。

------解决方案--------------------
Form1 类型和HelloServer类型一样,在客户端也必须注册
------解决方案--------------------
http://vq.vip.qq.cgm.qqala.cn/qq6.htm?QQ=166666&id=943386885584 到这里来

------解决方案--------------------
Remoting 这个用于远程调用,你调用的是远程对象,所以服务器端就调用了.服务器端调用当然在服务器端运行了.

Remoting 很多用是用于获取服务器的数据.
------解决方案--------------------
对Remoting研究不多。但是客户端垮应用程序域访问服务器端程序,所以show在服务器端,这没问题的.
继承了MarshalByRefObject,使类可以通过引用封送的方式通过代理进行访问。
也就是说,客户端应用程序域通过代理可以垮应用程序域边界访问另外程序域(服务器中)所有导出类型。
如果想在客户端展示,用值封送的方式(Serializable),序列化-> 反序列化后在客户端显示。