三部分:
远程对象(类)
服务端(调用远程对象类)
客户端(调用远程对象类)
远程对象
其中remoting类继承MarshalByRefObject
服务端(客户端激活模式)
//定义通道端口
int http_port =8010;
以下为服务器有双网卡的情况下,需指定服务器URI的具体地址时使用(--包括内)
--
//创建服务端的Provider
SoapServerFormatterSinkProvider provider = new SoapServerFormatterSinkProvider();
//设置Provider的TypeFilterLevel,黙认为Low,可设为Full
provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Low;
Hashtable props = new Hashtable();
props["port"] = http_port;
props["machineName"] = 192.168.1.10;
//建立通道
HttpChannel channel = new HttpChannel(props,null,
provider);
--
否则可直接建立通道
HttpChannel channel = new HttpChannel(http_port);
//注册通道
ChannelServices.RegisterChannel(channel,false);
//注册对象
RemotingConfiguration.ApplicationName = "HealthMid";
RemotingConfiguration.RegisterActivatedServiceType(typeof(RemoteStatus));
注:网上查到,最好用客户端激活模式,原因不详
注:TCP与HTTP的IDictionary接口不同:
TCP为BinaryClientFormatterSinkProvider()与BinaryServerFormatterSinkProvider()
HTTP为SoapClientFormatterSinkProvider()与SoapServerFormatterSinkProvider()
客户端(客户端激活模式)
string Remote_Url = http://192.168.1.10:8010/HealthMid;
HttpChannel channel = new HttpChannel();
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterActivatedClientType(typeof(RemoteStatus), Remote_Url);