views:

90

answers:

1

Is it possible in managed code to get a reference to an already running process (COM+ component) and call methods on it? Instead of instantiating a new object, is there a way to point to an already running instance of a COM object so that the .net code has a reference to the running process just as if it had instantiated it - to call methods on it as if it had newed one up in it's own app domain?

A: 

COM

It all depends on the COM component. If it is designed as a singleton (this is directly supported in ATL for instance) and is out of process then getting the same object is the only option.

On the other hand, most COM components provide no ability to do this, even if run out of process. A singleton broker/proxy component could own the single instance of the component in question.

Summary: it can be done, but only with the cooperation of the component the client code "instantiates" by overriding that instantiating to return the same object.

WCF

WCF could be another route. By default the WCF server runtime will instantiate a new instance for each call. But you can use attributes to override this, and serve all client requests in a single instance (and you have to handle the concurrency). Equally the class implementing the service contract could reference a singleton.

Richard