简体   繁体   English

将客户端创建的对象传递到服务器.net远程处理

[英]Passing client created object to server .net remoting

How can I pass my client-side object to my server object in .net remoting? 如何在.net远程处理中将客户端对象传递给服务器对象?

This is how I'm doing my test. 这就是我进行测试的方式。 On my class library: 在我的课程库中:

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";
  }
}

On my Server Application: 在我的服务器应用程序上:

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";

On my Client Application: 在我的客户应用程序上:

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

The error I encoutered was: Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed. 我遇到的错误是:由于安全限制,无法访问类型System.Runtime.Remoting.ObjRef。 Inner Exception: Request Failed. 内部异常:请求失败。

Please tell me what I'm doing wrong. 请告诉我我在做什么错。 Thanks! 谢谢!

I found out already what I'm doing wrong. 我已经发现我在做什么错。 The SampleClass should not have inherited the MarshalByRefObject. SampleClass不应继承MarshalByRefObject。

May be this can be of future reference to others. 也许这可以为将来的他人参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM