简体   繁体   English

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

[英].NET Remoting, passing objects into methods

I am writing a .NET Remoting application. 我正在编写.NET Remoting应用程序。 I have my dll, server, and client all working correctly. 我的dll,服务器和客户端都正常工作。 However, when I try to change my method call to take an object parameter instead of a simple type like an int, it complains with this error. 但是,当我尝试更改我的方法调用以获取对象参数而不是像int这样的简单类型时,它会抱怨此错误。

Type System.Runtime.Remoting.ObjRef and the types from it (such as System.Runtime.Remoting.ObjRef) are not permitted to be deserialized at this security level. 键入System.Runtime.Remoting.ObjRef及其中的类型(例如System.Runtime.Remoting.ObjRef)不允许在此安全级别进行反序列化。

The method is something like this. 方法是这样的。

public List<Orders> GetOrders(int UserID) { //Works

public List<Orders> GetOrders(Users user) { // Doesnt Work

[Serializable]
public class Users : MarshalByRefObject {

Now I have made the User class also, [Serializable] and given it MarshalByRefObject inheritance. 现在我已经创建了User类,[Serializable]并赋予它MarshalByRefObject继承。 Could this be my problem? 这可能是我的问题吗? I have tried removing [Serializable] from the User class and it complains cause it cant interpret it. 我试过从User类中删除[Serializable]并且它抱怨因为它无法解释它。

EDIT Ok, here is my client method. 编辑好的,这是我的客户端方法。

IChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel, false);
CustomType Server = (CustomType)Activator.GetObject(typeof(CustomType), "tcp://localhost:9934/CustomType");

Here is my server. 这是我的服务器。

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();

"are not permitted to be deserialized at this security level." “不允许在此安全级别反序列化。” is the significant part. 是重要的部分。

See the following for the answer 请参阅以下内容以获取答案

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

Set the following on both client and server: 在客户端和服务器上设置以下内容:

typeFilterLevel="Full" in the Formatter tag formatter标记中的typeFilterLevel =“Full”

Actually, .NET remoting is an obsolete technology. 实际上,.NET远程处理是一种过时的技术。 You should take a look at WCF instead. 你应该看一下WCF。

Regarding your actual problem: Your probably running your application in a trust-level that is too low. 关于您的实际问题:您可能在信任级别太低的情况下运行您的应用程序。
The Users class should be serializable, but, if it does not contain any methods that should run at the server, it should not derive from MarshalByRefObject Users类应该是可序列化的,但是,如果它不包含应该在服务器上运行的任何方法,则它不应该派生自MarshalByRefObject

Ensure both the server and client configuration set the typeFilterLevel property to Full 确保服务器和客户端配置都将typeFilterLevel属性设置为Full

or have your User class implement ISerializable 或让您的User类实现ISerializable

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

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

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