C# 在C语言中将远程对象传递给远程方法
我试图将远程对象作为参数传递给远程方法,但当远程对象尝试在接收到的远程对象上运行方法时,会出现安全异常 这是一个示例远程对象:C# 在C语言中将远程对象传递给远程方法,c#,remoting,C#,Remoting,我试图将远程对象作为参数传递给远程方法,但当远程对象尝试在接收到的远程对象上运行方法时,会出现安全异常 这是一个示例远程对象: public class SharpRemotingDLL : MarshalByRefObject { public String getRemoteMessage(SharpRemotingDLL server) { // the exception is raised here return server.getMe
public class SharpRemotingDLL : MarshalByRefObject
{
public String getRemoteMessage(SharpRemotingDLL server)
{
// the exception is raised here
return server.getMessage();
}
public String getMessage()
{
return "Hello World!";
}
}
这是server starter,其中两个实例正在运行,一个在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方法?我以前编写过此类代码,但从未尝试以这种方式将服务器对象传递给另一个服务器对象。我不是安全专家,但我能感觉到为什么这可能是不允许的 您应该直接从Server1获取消息,而不是要求另一个远程服务器返回消息。换句话说,您的消息检索逻辑需要位于客户端。vbigiani 这篇文章应该对您的问题有所帮助: 如果这不起作用,您可以在这里获得几个相关的谷歌点击:
这只是一些演示问题的示例代码。在我的实际代码中,SharpRemotingDLL是一个导出基本文件操作CreateFile、ReadFile等的类,我使用类似的Syntax在两台服务器之间实现CopyFile和MoveFile:客户端使用server1.CopyFilefoo.txt,server2 CopyFile方法:public void CopyFileString名称,SharpRemotingDLL服务器{server.WriteFilename,this.ReadFilename;}我无法准确翻译,因为我的操作系统是意大利语的,用谷歌搜索错误消息没有帮助。无论如何: