【问题标题】:Passing client created object to server .net remoting将客户端创建的对象传递给服务器 .net 远程处理
【发布时间】:2010-07-07 07:23:03
【问题描述】:

如何在 .net 远程处理中将客户端对象传递给服务器对象?

这就是我进行测试的方式。 在我的类库中:

public interface IServer 
{
  bool SubmitMessage( ISampleClass sample ); 
}

[Serializable]
public Server : MarshalByRefObject , IServer 
{
   Public Server() 
   {
   }
   public bool SubmitMessage( ISampleClass sample )
   {
     return true;
   }
}


public interface ISampleClass 
{
  string GetName();
}

[Serializable]
public class SampleClass : MarshalByRefObject , ISampleClass
{
  public SampleClass()
  {
  }
  public string GetName()
  {
    return "test";
  }
}

在我的服务器应用程序上:

IChannel channel = new TcpChannel(9988);
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisteredWellKnownServiceType( typeof(Testing.Server) ,"testremote",WellKnownObjectMode.Singleton);
RemotingConfiguration.RegisterActivatedServiceType(typeof(Testing.SampleClass));
RemotingConfiguration.ApplicationName = "TestRemote";

在我的客户端应用程序上:

Type type = typeof(Testing.Server);
Testing.IServer server = (Testing.IServer)Activator.GetOject(type,"tcp://localhost:9988/testremote");
RemotingConfiguration.RegisteredActivatedClientType(typeof(Testing.SampleClass), "tcp://localhost:9988/TestRemote");
Testing.SampleClass test = new Testing.SampleClass(); // proxy class
server.SubmitMessage(test); // Error here

我遇到的错误是: 由于安全限制,无法访问类型 System.Runtime.Remoting.ObjRef。 内部异常:请求失败。

请告诉我我做错了什么。谢谢!

【问题讨论】:

    标签: c# .net remoting


    【解决方案1】:

    我已经发现我做错了什么。 SampleClass 不应继承 MarshalByRefObject。

    这可能是将来对其他人的参考。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-27
      相关资源
      最近更新 更多