>>可是每当调用ClassObj的aaa方法时,这个方法所完成的功能“显示对话框”总是显示在服务器端
实际对象是在服务器端建立的,当然在服务器端显示啦!>>难道方法不能通过通道传输吗,如果这样的话,这个方法所引发的其它方法也通通不能通过通道传输吗?
不太清楚你问什么。控制服务器窗体,可以用reference解决!
把你的程序 稍微改一改:
1.建立一个类库项目:HostObj继承于System.MarshalByRefObject
using System;
using System.Windows.Forms;
namespace HostObj
{
public class ClassObj : System.MarshlByRefObject
{
   //MyForm是你自己写的窗体类,比如它有一个public TextBox txt_info的成员
   public MyForm form1;
   public HostObj()
      {
form1 = new MyForm();
form1.Show();
       }
   publci aaa()
      {  
//MessageBox("显示一个对话框");
form1.txt_info.Text = "Hello Remoting!";
      }
}
}2.建立一个服务器项目Hostusing System;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp; 
using HostObj;public class Host
{
   public static Main()
   {
     TcpServerChannel channel=new TcpServerChannel(8086);
     ChannelServices.RegisterChannel(channel);//注册服务器通道
     RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClassObj),"Hi",WellKnownObjectMode.SingleCall);//注册远程服务对象类型
     System.Console.WriteLine("hit to exit");
     System.Console.ReadLine(); //等待
   }
}3.建立一个客户端项目using System;
using System.Windows.Forms;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp; 
using HostObj;public class Client
{     public static void Main()
    {
      ChannelServices.RegisterChannel(new TcpClientChannel());
      ClassObj obj=(Hello)Activator.GetObject(typeof(HostObj.ClassObj),"tcp://localhost:8086/ReturnName");
//以下有两种方法 可以控制服务器端窗体中的TextBox      
//方法1
obj.aaa();
//方法2
obj.form1.txt_info.Text = "Hello Remoting!"; //如果你所说的 “过通道传输”,是指在客户端显示服务器端运算的结果
//那么可以这样做
//注意,这是在客户端的代码,所以在客户端显示(觉得你对remoting的应用理解有些错误)
MessageBox.Show(obj.txt_info.Text);
}

解决方案 »

  1.   

    简尔言之,我想问一下,如果我的窗体程序如MYFORM.dll是放在服务器端,客户端要怎么样调用它,是不是用Net Remoting可以完成呢,如果可以的话要怎么做?
      

  2.   

    客户端也得放一个你可以把里面的代码删掉,只留下接口,再单独编译一次,如:
    public void aaa()
    {
    }
    public int add(int a,int b)
    {
    return 0;
    }
    这样相对安全一些但通常不用 form 来做这个RemoteObject
    就像Windows Service, COM+ 一样,不需要被看到
    高效集中处理客户端数据 才是组件的用处