将客户端创建的对象传递给服务器 .net 远程处理
如何将客户端对象传递到 .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 类型。 内部异常:请求失败。
请告诉我我做错了什么。谢谢!
How can I pass my client-side object to my server object in .net remoting?
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.
Inner Exception: Request Failed.
Please tell me what I'm doing wrong. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经发现我做错了什么。 SampleClass 不应继承 MarshalByRefObject。
也许这可以为其他人将来提供参考。
I found out already what I'm doing wrong. The SampleClass should not have inherited the MarshalByRefObject.
May be this can be of future reference to others.