Hi all,
the COM component that needs to be service-enabled can only work in 1
thread. That means, the thread that creates the COM object is the only
thread where I can use this COM component. I can only create 1
instance of it. So what I did is: used the IDesign's sample to make
sure that every request is executed in the same thread; and making
sure that only 1 call at a time can execute. Because this is a
potential bottleneck, only fast COM calls are done this way. The calls
that take a while to complete will be queued to another server where a
second instance is running. (PS - I'm service enabling the Protean ERP
COM API)
This doesn't answer the question about what type of COM object it is, with
this I mean what's his "apartment type"?
The apartment type can be found back in the registry or by using
OLEVIEW.EXE.
As apartment type you can have "Single", "Apartment", "Both" and "Free",
only both and Free can live in a MTA, the other need an STA thread to live
in.
Now, because all thread created by WCF will enter the MTA, the objects of
type single and Apartment will get instantiated on a COM managed STA thread
as there are no other STA thread is available in the service (WCF) process.
In this case, all accesses from the MTA threads will need to get marshaled
to the STA thread where the object lives. This marshaling requires two
important things:
1. The STA thread needs a message pump, WCF doesn't pump a message queue, so
you'll have to create a separate thread initialized to enter an STA and you
will have to provide the message pump.
2. The interface needs marshaling support from typelib marshaler, COM
objects of type "Single" don't have this marshaling, so they are not usable
in this context.
So this leaves you with only "apartment" and "both" COM types as usable,
provided they are created on a separate thread as in 1 above.
"Free" COM types will live on the callers thread in the MTA, that means each
client will have it's own COM instance which is not what you want.
Willy.