c# - 如何在 .NET Remoting 中远程处理事件?

标签 c# .net events .net-remoting

我有一个包含事件的远程处理类。但是当我尝试在客户端设置这些事件的处理程序时,我收到异常。我的代码如下所示:

    //In common library
    class RemoteClass : MarshalByRefObject
    {
    public event EventHandler SomeEvent = null;

    public void SomeMethod () {}
    }

    //On client-side
    RemoteClass r = (RemoteClass) RemotingServer.Connect (typeof(RemoteClass), "myURL");

    r.SomeMethod (); //Everything is OK here.

    r.SomeEvent += delegate (object o, EventArgs e) { }; //Exception:Type 

System.DelegateSerializationHolder 及其派生类型(例如 System.DelegateSerializationHolder)不允许在此安全级别进行反序列化。

我做错了什么?

最佳答案

https://web.archive.org/web/20141009214120/http://msdn.microsoft.com/en-us/library/61w7kz4b(v=vs.80).aspx

In the .NET Framework, the default security level for distributed communication (remoting) is low. This affects passing the user-defined object type to remote methods. You might need to adjust the default security level to full in some cases to allow serialization of objects.

如果您使用 ASP.Net,请按以下步骤设置安全(信任)级别:

http://msdn.microsoft.com/en-us/library/ff648344.aspx

关于c# - 如何在 .NET Remoting 中远程处理事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7608826/

相关文章:

c# - 无法弄清楚异常消息

.net - 找不到请求的.Net Framework数据提供程序

events - DDD : Entity with collection of value objects - One event or multiple?

c# - Task.Faulted 和 Task.Exception

c# - 在 aspx 文件中包含 webservice 函数

C# .NET 4.0 WCF MessageSecurityException,使用服务时出现 "Security header is empty."

javascript - 停止监听或删除 Image() 对象 onload 事件的事件

c# - 委托(delegate)和事件之间的关系是什么?

c# - 在 PushSharp 4.0 中构建 GCM 消息

javascript - javascript对html进行更改后如何获取html源(无需浏览器)