简体   繁体   中英

How to remote events in .NET Remoting?

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 (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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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