Remoting 在服务器端和客户端激活的激活方式

一、客户端激活方式

  服务器端实现:

    TcpChannel channel = new TcpChannel(9001);

    ChannelServices.RegisterChannel(channel, false);

    RemotingConfiguration.ApplicationName = "ServerObject";
    RemotingConfiguration.RegisterActivatedServiceType(typeof(NetRemotingServer.ServerObject));

  客户端实现:

    TcpChannel channel = new TcpChannel();

    ChannelServices.RegisterChannel(channel,false);
    RemotingConfiguration.RegisterActivatedClientType(typeof(NetRemotingServer.ServerObject), "tcp://localhost:9001/ServerObject");

    NetRemotingServer.ServerObject so = (NetRemotingServer.ServerObject)Activator.CreateInstance(typeof(NetRemotingServer.ServerObject), new object[1] { "aaa" }, null);//或者  NetRemotingServer.ServerObject so = new NetRemotingServer.ServerObject();
    so.WriteName();

 

二、服务器端激活方式

  服务器端实现:

    TcpChannel channel = new TcpChannel(9001);

    ChannelServices.RegisterChannel(channel, false);

    RemotingConfiguration.RegisterWellKnownServiceType(typeof(NetRemotingServer.ServerObject), "ServerObject", WellKnownObjectMode.SingleCall);
    channel.StartListening(new NetRemotingServer.ServerObject());

  客户端实现:

      TcpChannel channel = new TcpChannel();

    ChannelServices.RegisterChannel(channel,false);
    RemotingConfiguration.RegisterWellKnownClientType(typeof(NetRemotingServer.ServerObject),"tcp://localhost:9001/ServerObject");

 

    NetRemotingServer.ServerObject so = (NetRemotingServer.ServerObject)Activator.GetObject(typeof(NetRemotingServer.ServerObject), "tcp://localhost:9001/ServerObject");

posted @ 2012-01-05 11:29  不弃的追求  阅读(602)  评论(0编辑  收藏  举报