繁体   English   中英

.NET Remoting,将对象传递给方法

[英].NET Remoting, passing objects into methods

我正在编写.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();

“不允许在此安全级别反序列化。” 是重要的部分。

请参阅以下内容以获取答案

http://www.codeproject.com/Articles/4363/NET-Remoting-in-Simple-English-Really-it-s-that-s

在客户端和服务器上设置以下内容:

formatter标记中的typeFilterLevel =“Full”

实际上,.NET远程处理是一种过时的技术。 你应该看一下WCF。

关于您的实际问题:您可能在信任级别太低的情况下运行您的应用程序。
Users类应该是可序列化的,但是,如果它不包含应该在服务器上运行的任何方法,则它不应该派生自MarshalByRefObject

确保服务器和客户端配置都将typeFilterLevel属性设置为Full

或让您的User类实现ISerializable

有关.NET Remoting序列化安全性的MSDN文档。

暂无
暂无

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

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