【发布时间】:2024-06-08 20:20:01
【问题描述】:
我正在尝试将远程对象作为参数传递给远程方法,但是当远程对象尝试在接收到的远程对象上运行方法时,我得到了一个安全异常。
这是一个示例远程对象:
public class SharpRemotingDLL : MarshalByRefObject
{
public String getRemoteMessage(SharpRemotingDLL server)
{
// the exception is raised here
return server.getMessage();
}
public String getMessage()
{
return "Hello World!";
}
}
这是服务器启动器(它的两个实例正在运行,一个在 127.0.0.10025 上,另一个在 127.0.0.10026 上):
public static int Main(string[] args)
{
TcpServerChannel channel;
channel = new TcpServerChannel(10025);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(SharpRemotingDLL),
"SharpRemotingDLL",
WellKnownObjectMode.Singleton);
Console.ReadLine();
return 0;
}
这是客户端:
static void Main(string[] args)
{
SharpRemotingDLL server0 = (SharpRemotingDLL)
Activator.GetObject(typeof(SharpRemotingDLL),
"tcp://localhost:10025/SharpRemotingDLL");
SharpRemotingDLL servers[1] = (SharpRemotingDLL)
Activator.GetObject(typeof(SharpRemotingDLL),
"tcp://localhost:10026/SharpRemotingDLL");
Console.WriteLine(server0.getRemoteMessage(server1));
}
如何正确地将 server1 作为参数传递给 getRemoteMessage 方法?
【问题讨论】: