这节来谈谈关于Remoting的简单配置
服务端配置
<?xml version="1.0"?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="9999"/>
</channels>
<service>
<wellknown mode="Singleton" type="Server.MyServiceImpl,Server" objectUri="myservice.rem"/>
</service>
</application>
</system.runtime.remoting>
</configuration>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="9999"/>
</channels>
<service>
<wellknown mode="Singleton" type="Server.MyServiceImpl,Server" objectUri="myservice.rem"/>
</service>
</application>
</system.runtime.remoting>
</configuration>
服务端调用
RemotingConfiguration.Configure("Server.exe.config",false);
Console.WriteLine("Server is Running...");
Console.WriteLine("Server is Running...");
当服务开启后,可以通过控制台查看端口是否开始监听,运行-》cmd-》netstat -a ,通过查看命令显示的信息,判断你所设置的服务是否开启
客户端配置
<?xml version="1.0"?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp"/>
</channels>
<client>
<wellknown type="ShareDLL.IMyService,ShareDLL" url="tcp://localhost:9999/myservice.rem"/>
</client>
</application>
</system.runtime.remoting>
</configuration>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp"/>
</channels>
<client>
<wellknown type="ShareDLL.IMyService,ShareDLL" url="tcp://localhost:9999/myservice.rem"/>
</client>
</application>
</system.runtime.remoting>
</configuration>
客户端调用
RemotingConfiguration.Configure("Client.exe.config", false);
WellKnownClientTypeEntry[] types = RemotingConfiguration.GetRegisteredWellKnownClientTypes();
if (types.Length > 0)
{
ShareDLL.IMyService service = (ShareDLL.IMyService)Activator.GetObject(types[0].ObjectType,
types[0].ObjectUrl);
try
{
Console.WriteLine(service.SayHello("mike"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
else
Console.WriteLine("no service reigstered");
WellKnownClientTypeEntry[] types = RemotingConfiguration.GetRegisteredWellKnownClientTypes();
if (types.Length > 0)
{
ShareDLL.IMyService service = (ShareDLL.IMyService)Activator.GetObject(types[0].ObjectType,
types[0].ObjectUrl);
try
{
Console.WriteLine(service.SayHello("mike"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
else
Console.WriteLine("no service reigstered");
更多关于Remoting的配置,可以参考其他