.NET分布式Remoting学习,不错的Remoting教程(2)
客户端:
HttpChannel httpchannel = new HttpChannel();
ChannelServices.RegisterChannel(httpchannel);
Add addmethod1 = (Add)Activator.GetObject(typeof(Add), "http://localhost:8081/add");
被下面的配置文件代替
Code
1<?xml version="1.0" encoding="utf-8" ?>
2<configuration>
3 <system.runtime.remoting>
4 <application>
5 <client>
6 <wellknown type="RemotingToAdd.Add,General" url="http://localhost:8081/add" />
7 </client>
8 <channels>
9 <channel ref="http" port="0"></channel>
10 </channels>
11 </application>
12 </system.runtime.remoting>
13</configuration>
用RemotingConfiguration.Configure(@"Client.exe.config");调用配置文件。
服务端:
Code
TcpChannel tcpchannel = new TcpChannel(8080);
HttpChannel httpchannel = new HttpChannel(8081);
ChannelServices.RegisterChannel(tcpchannel);
ChannelServices.RegisterChannel(httpchannel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Add), "add", WellKnownObjectMode.Singleton);
被下面的配置文件代替:
Code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="Singleton" type="General,RemotingToAdd.Add" objectUri="add"/>
</service>
<channels>
<channel port ="8081" ref="http"></channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
用RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);调用配置文件
源码下载