views:

16

answers:

1

Hello,

I have a Windows Service written in C# that controls a device connected to the computer by RS232 (gathers data and allows to control the device). It's named DeviceService and it's working properly. Now other applications use it by WCF services.

But now I need to expose some of functionalities as COM+ Component, so applications in C++ can communicate with this windows service (and get real-time data from it).

(I know that there might be better ways to do this but that's the requirement that can't be changed. It must be via COM+).

The problem is: when I create such a component in the DeviceService and activate it on the client it sees no data. For instance: static variables in Windows Service (DeviceService) return null for the component that is defined in the same assembly. Like it was another instance / context.

What is the proper way to host a COM+ component inside a windows service? So they share the same context (static variables).

A: 

A quick glance through the contents of ".NET and COM: The Complete Interoperability Guide" (which is based on .NET 1, but COM interop hasn't changed much) via Safari Books Online doesn't reveal anything.

Therefore I would consider creating the service part with WCF, and then create a client library that exposes a COM interface locally. (So replacing the in-process COM proxy of DCOM and COM+ with a COM -> .NET CCR and then doing everything else in pure .NET.)

The client library's COM interface can of course be registered in component services to be seen as COM+ (but unless the functionality you are providing needs some COM+ service this doesn't achieve much).

Richard
It looks like a work-around not a good solution. Such solution would give a great deal of extra code.
@nandrew: You have the WCF server already, so create a client proxy and a set of wrapper types (optimised for exposure via COM). I.e. you need one set of classes only (which you're going to need whatever).
Richard
Still, it's an ugly workaround and not a real solution.