开发者

EventHandler and remoting

In my application there is a clss containing an event of type EventHadler and this class should be remoted in another application (it must treat those events). 开发者_如何学编程First parameter of this EventHandler is object o (object in which event was fired). Is this parameter make sense in another application or not? These events will be calling ? Sorry for complicated question but I can't express my thought clearly while.


It depends on whether or not anyone is going to use the sender parameter.

If they are, then it depends on what the object is; if it is something that is only significant to the app domain that the object is in, then you need to make sure that the object derives from MarshalByRefObject so that the calls from the client can be remoted back to the instance on the server.

If it makes sense to send the sender by value, then you have to make sure that it is serializable.

That said, events over remoting is usually a bad idea. A better solution is to create an assembly with an interface that can be shared between the client and the server. This interface contains methods that would be implemented on the client (with a base class of MarshalByRefObject) and an instance of that implementation would be passed to the service. The service would then store this reference and make the calls on the implementations of the interface whenever you wanted to raise an "event".

WCF abolishes the concept of events over distributed calls, opting for exactly this pattern, using a callback interface when the client wants to be notified of events by the server.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜