求Remoting怎么使用?最好给代码Thanks

解决方案 »

  1.   

    所使用dll代码:
    public class gxyremoting:System.MarshalByRefObject,gxyremotinginterface.remotinginterface
    {
    public gxyremoting()
    {
    Console.WriteLine("\n启动一个实例");
    }
    public DataSet GridData(string DataBaseName,string TableName)
    {
    Console.WriteLine("\n连接到数据库"+DataBaseName+"的表"+TableName);
    string connetstring="workstation id=GAOXIAOYONG;packet size=4096;user id=sa;data source=GAOXIAOYONG;persist security info=False;initial catalog="+DataBaseName;
    System.Data.SqlClient.SqlConnection conn=new SqlConnection(connetstring);
    string strsql="select * from " +TableName;
    DataSet ds=new DataSet();
    System.Data.SqlClient.SqlDataAdapter adap=new SqlDataAdapter(strsql,conn);
    adap.Fill(ds);
    return ds;

    }
    }
      

  2.   

    客户端代码:
    ChannelServices.RegisterChannel(new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel());
    ChannelServices.RegisterChannel(new System.Runtime.Remoting.Channels.Http.HttpClientChannel());
    rf= (remotinginterface)Activator.GetObject(typeof(remotinginterface),"HTTP://192.168.0.123:9001/gxyremoting");
    if( rf==null)
    {
    rf= (remotinginterface)Activator.GetObject(typeof(remotinginterface),"TCP://192.168.0.123:9000/gxyremoting");
    }
      

  3.   

    服务器端代码:
    TcpServerChannel tcpc=new  TcpServerChannel(9000);
    System.Runtime.Remoting.Channels.Http.HttpServerChannel httpc=new System.Runtime.Remoting.Channels.Http.HttpServerChannel(9001);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(gxyremoting),"gxyremoting",WellKnownObjectMode.SingleCall);
    ChannelServices.RegisterChannel(tcpc);
    ChannelServices.RegisterChannel(httpc);
    Console.Write("启动服务器");
    Console.ReadLine();