【发布时间】:2012-03-05 07:15:43
【问题描述】:
我正在编写一个 .NET Remoting 应用程序。我的 dll、服务器和客户端都正常工作。但是,当我尝试更改我的方法调用以采用对象参数而不是像 int 这样的简单类型时,它会抱怨此错误。
键入 System.Runtime.Remoting.ObjRef 及其类型(例如 System.Runtime.Remoting.ObjRef) 不允许反序列化 在这个安全级别。
方法是这样的。
public List<Orders> GetOrders(int UserID) { //Works
public List<Orders> GetOrders(Users user) { // Doesnt Work
[Serializable]
public class Users : MarshalByRefObject {
现在我也创建了 User 类,[Serializable] 并赋予它 MarshalByRefObject 继承。这可能是我的问题吗?我已经尝试从 User 类中删除 [Serializable] 并且它抱怨导致它无法解释它。
编辑 好的,这是我的客户端方法。
IChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel, false);
CustomType Server = (CustomType)Activator.GetObject(typeof(CustomType), "tcp://localhost:9934/CustomType");
这是我的服务器。
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 9934;
TcpChannel channel = new TcpChannel(props, null, provider);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(CustomType), "CustomType", WellKnownObjectMode.Singleton);
Console.WriteLine("Server is initialized");
Console.ReadLine();
【问题讨论】:
-
您是否尝试过从 Users 类中删除
MarshalByRefObject? -
我还没有完全试过,让我回去确认一下
-
当我删除 MarshalByRefObject 时它没有帮助,谢谢!
-
由于您是第一个发布解决方案 L.B 的人,如果您创建答案而不是评论,我会给予您信任。
-
谢谢,知道您解决了问题就足够了。
标签: c# .net remoting serializable