简体   繁体   English

客户端对象(代理)如何注册要在服务器端触发的事件?

[英]How a client side object (Proxy) register to an event to be fired on the server side?

I would like to make a class where the client side (proxy) of the instantiated object can register to an event (or delegate) and be informed whenever this event is fired on the server side. 我想创建一个类,在该类中,实例化对象的客户端(代理)可以注册到事件(或委托),并在服务器端激发此事件时得到通知。

I tried directly but I get a SecurityException informing me that System.DelegateSerializationHolder cannot be serialized at this security level. 我直接尝试过,但是收到了SecurityException通知我System.DelegateSerializationHolder无法在此安全级别进行序列化。

Is there a way around this? 有没有解决的办法?

Example: 例:

MyClass proxy = Activator.GetObject(typeof(MyClass ), uri) as MyClass;
proxy.OnMyEvent += new MyEventHandler(this.Callback);

No. Not directly anyway. 不。不是直接。

Your choices would be to either have the client call back to the server and register a with it a port for out of band controls from the server. 您的选择是让客户端回叫服务器,并向其注册一个端口,以从服务器进行带外控制。 This could open up all sorts of security concerns. 这可能会引发各种安全问题。

Probably the best way would be to have the client poll the server to see if any events need to be processed. 最好的方法可能是让客户端轮询服务器以查看是否需要处理任何事件。 This leaves the control of information requests in the clients domain, and is how Microsoft Exchange and other products I've worked with tend to handle this scenario. 这样就可以控制对客户端域中信息请求的控制,这就是我使用过的Microsoft Exchange和其他产品倾向于处理这种情况的方式。

Yes, it is possible, but it's deactivated by default. 是的,可以,但是默认情况下它是禁用的。

The default .net Remoting deserialization level is Low , which does not allow Delegates to be passed over the Remoting boundary. 默认的.net Remoting反序列化级别为Low ,这不允许将代理传递通过Remoting边界。 You can create a custom BinaryServerFormatterSinkProvider with a deserialization level of Full and pass this provider to your channel (on the server side). 您可以创建反序列化级别为Full的自定义BinaryServerFormatterSinkProvider,然后将此提供程序传递到您的通道(在服务器端)。

Here's a VB.NET example; 这是一个VB.NET示例; see the MSDN article on Automatic Deserialization in .NET Framework Remoting for a C# example. 有关 C#示例,请参见有关.NET Framework Remoting中的自动反序列化的MSDN文章

Dim myChannel = New TcpServerChannel("", myPort, _
                                     New BinaryServerFormatterSinkProvider() With {.TypeFilterLevel = Runtime.Serialization.Formatters.TypeFilterLevel.Full})

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

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