Remoting跨边界开发

之前用了Remoting技术实现了不同服务器之间的数据交互,最近闲下来然后整理了一下。

一、Remoting开发分为三个部分:远程对象、远程对象的宿主程序、客户端。

1、远程对象必须继承自MarshalByRefObject

2、远程对象需要一个运行的宿主程序,注册此对象服务

3、客户端需要引用远程对象的dll

二、服务端

TcpServerChannel channel = new TcpServerChannel(10099);
    ChannelServices.RegisterChannel(channel);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject),
     "RemoteObject", WellKnownObjectMode.SingleCall);
     System.Console.ReadLine();

三、客户端

1、将远程对象引用到客户端工程,

2、// 注册信道 http/tcp/icp(本地),多信道时名字不能相同
            IDictionary httpProp = new Hashtable();
            httpProp["name"] = "111";
            httpProp["port"] = 0;

            channel = new HttpChannel(httpProp,
            new SoapClientFormatterSinkProvider(),
            new SoapServerFormatterSinkProvider());

            ChannelServices.RegisterChannel(channel, false);
            #endregion

            lsobj = (IServerObject)Activator.GetObject(typeof(IServerObject), "http://192.168.1.174:10099/TestRemoting");//IP地址需替换

          returnvalue = lsobj.LetMeDo(connand).ToString();//接收从远程对象返回的结果信息

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值