我试图将远程对象作为参数传递给远程方法,但当远程对象尝试在接收到的远程对象上运行方法时遇到安全异常。将远程对象传递给远程方法在C#中
这是一个示例的远程对象:
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.10026运行,一个在127.0.0.10025,其他):
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方法?
这只是一些示例代码来演示问题。在我的真实代码中,SharpRemotingDLL是一个导出基本文件操作(CreateFile,ReadFile等)的类,我使用类似的合成器来实现两个服务器之间的CopyFile和MoveFile: 客户端使用 server1.CopyFile(“foo。 TXT”,服务器2) 的CopyFile方法: 公共无效的CopyFile(字符串名称,SharpRemotingDLL服务器) { server.WriteFile(姓名,this.ReadFile(名)); } – vbigiani 2009-05-31 17:14:26
错误信息的确切用词是什么? – 2009-05-31 17:37:29