[quoted text, click to view] "Ben" <Ben@discussions.microsoft.com> wrote in message
news:8D55E138-CCA4-463C-85C9-B5AC0A2436AC@microsoft.com...
> Yes, but then you end up with a different instance of the component dont
> you?!?!?
>
> In this case I want to talk to the COM instance that is already running
> because there is data in it.
>
> Or is there a way in .NET to get hold of that instance and talk to it the
> way you would talk to a .NET component?
>
> Note we also want non .NET software to be able to talk to the same
> instance
> of it, which they can only do by talking to it as a COM object by finding
> it
> in the running object table.
A .NET client must call Marshal.GetActiveObject to connect to a running
instance, note that YOU are responsible for registering the instance in the
ROT at the server side, this is not done automatically.
Anyway, this is old hat, much better and a lot easier is to use
System.Enterprises and derive your class from ServicedComponent. All you
need to do is tag your assembly, interface and class with the right
attributes in order to run this class in a COM+ surrogate process as a
pooled singleton. Attributes you need to set are JustInTimeActivation,
ObjectPooling with both MinPoolSize and MinPoolSize set to 1.
This way the class object becomes the one and only instance clients can
connect with. Object life-time and state management can be implemented by
overriding the ServicedComponent methods Activate, Deactivate,
CanBePooled....
A .NET client can early bind using the metadata supplied by the interface,
while COM clients can early bind using the typelib created when registering
the .NET assembly with the COM+ catalog (using regsvcs.exe), there is no
need for the COM client to bind to a running object, as there is only one
single object of that type running, both .NET and COM clients will always
connect to the same instance.
Willy.