开发者

How to remote events in .NET Remoting?

开发者 https://www.devze.com 2023-04-09 20:22 出处:网络
I have a class for remoting which contains events. But when I am trying to set handler for those events on the client side I receive exception. My code looks like:

I have a class for remoting which contains events. But when I am trying to set handler for those events on the client side I receive exception. My code looks like:

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

    public void SomeMethod () {}
    }

    //On client-side
    RemoteClass r = (RemoteClass) RemotingServer.Connect开发者_如何学Go (typeof(RemoteClass), "myURL");

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

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

System.DelegateSerializationHolder and the types derived from it (such as System.DelegateSerializationHolder) are not permitted to be deserialized at this security level.

What do I do wrong?


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.

If you're in ASP.Net, here's how to set the security (trust) level:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号