Suppose we have two Wellknown singleton remoting objects.
the former is instantiated by the latter, and sends events to it.
Let's call S_A and S_B the two wellknown remoting objects.
These object reside on two different appdomains. S_B is instantiated by S_A.
S_B is the source of events, and S_A has to receive them.
Note that S_A is a wellknown on his turn.
After S_B is instantiated in S_A, an exception is thrown:
Wellknown objects cannot marshal themselves in their constructor, or perform
any action that would cause themselves to be marshalled (such as passing the
this pointer as a parameter to a remote method)
The error happens at runtime, either when a handler is added for an S_B event or as soon as S_B is instantiated.
To understand why this happens, a first resume of how events works is useful.
Events are simple to use. What happens behind the curtains, is that a function is called on the target (the object handling the event -S_A-) by the sender of the event (S_B).
Since we are talking about wellknown server objects, what happens when S_B sends an event to S_A, is:
the remoting server (S_B) becomes a client of S_A (in fact S_B is calling a function on S_A) .
The exception is thrown because the wellknown object S_B is a SERVER fof S_A, so it is not allowed to use it as also as CLIENT. This is not allowed by remoting. It is allowed elsewhere.
SOLUTION :
Create a new class (C_C). Inside this class instantiate the wellknown S_B and receive his events here. S_A will instantiate C_C and receive events from it. C_C can become a client of S_A without problem since it is not a wellknown object.
No comments:
Post a Comment