How can I create a proxy for a remote object not received from MarshalByRefObject?

In AppDomain A

I have an object of o

type T

. T

is not Serializable

and is not derived from MarshalByRefObject

. The type is T

provided by the plugin host over which I have no control.

I would like to create an AppDomain B

and pass the proxy to the o

method in B

, but stumped: how to create a proxy?

The method in B

must be able to refer to methods on o

and read properties, etc. The results of these methods should be approximated in a similar manner.

+2


source to share


3 answers


I suggest that you create a correct proxy object that implements the same interface as the object you are trying to proxy and also inherits from MarshalByRefObject. Then you remove the proxy object. On the server side, the proxy is delegating your object.

Depending on your requirements, the server object will contain your object as static (all clients see the same object) or as non-static (each client gets a new copy).



In the case of a static member, you need to create a proxy on the server and initialize it with your object, or the first dedicated proxy (when the first client connects) creates your object and initializes itself. I used the first one.

Of course, don't forget about renting.

+5


source


If you need a proxy, your best bet is probably to encapsulate the object inside a type that inherits from MarshalByRefObject

(as a private field) and that has public methods, etc., to make it usable; facade, essentially.



If you want serialization - I would use a DTO that is associated with an object, but with a separate (serializable) type. Just submit the state and restore the actual type on the other end.

+3


source


You can not. The only way to communicate between AppDomains is to use a proxy or use a copy (that is, serializable).

Can you wrap your type in a proxy that inherits from MarshalByRefObject

and use instead?

+2


source







All Articles