如果在服务器端注册远程对象,则需要在服务器端的app.config中添加如下信息:
<system.runtime.remoting>
<application>
<service>
<wellknown type="CardServer.Service.CardServiceImpl,CardServer" objectUri="CardService" mode="SingleCall" />
</service>
<channels>
<channel ref="tcp" port="8001"/>
</channels>
</application>
</system.runtime.remoting>
同时,需要在服务器端程序中添加 RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
在客户端的app.config中添加如下信息:
<appSettings>
<add key="ServiceURL" value="tcp://192.168.0.111:8001/CardService"/>
</appSettings>
<system.runtime.remoting>
<application>
<service>
<wellknown type="CardServer.Service.CardServiceImpl,CardServer" objectUri="CardService" mode="SingleCall" />
</service>
<channels>
<channel ref="tcp" port="8001"/>
</channels>
</application>
</system.runtime.remoting>
同时,需要在服务器端程序中添加 RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
false),并添加using System.Runtime.Remoting引用;
在客户端的app.config中添加如下信息:
<appSettings>
<add key="ServiceURL" value="tcp://192.168.0.111:8001/CardService"/>
</appSettings>
如若在同一台电脑上测试服务器端接口程序,则ServiceURL的value设置为本机的ip地址,端口号为服务器端设置的port="8001"。然后,分别运行服务器或客户端下bin文件->debug文件下的.exe程序,另一程序(客户端或服务器)打断点调试,分析运行结果。
注:1、类库工程dll,若更改该dll,在其他工程中引用的该dll若不想每次重新添加,可以通过添加引用,进入引用管理界面,在界面左侧选中Projects,添加该dll,
后续该dll更改后,添加到其他工程的dll自动更改,不需要再次添加。
2、查看服务器端口是否启动,通过cmd->netstat -ano命令查看。
3、服务器和客户端在同一台电脑上联调,可以把tcp设置为:127.0.0.1,对应的端口号大于1024即可。