Creating COM+ objects using .NET is easy. Follow these steps:
Write the class as shown in the code example following these steps. It is especially important to bring in the following namespaces:
using System;
using System.Runtime.InteropServices;
using System.EnterpriseServices;
using System.Reflection;
Your class must inherit ServicedComponent.
Sign your class using sn.exe, as follows:
sn.exe --k MyKey.snk
Modify the AssemblyInfo.cs file on the following attribute:
[assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
Use regsvcs to register the DLL in COM+ as a library application. This means that it runs in the process of the process that instantiates it.
regsvcs /appname:SRX MyDLL.DLL
If you want to register the object as service application, you must open the application with the Component Services snap-in and change the application to a server application using the Activation tab.
The following example demonstrates creating COM+ objects in .NET.
using System; using System.EnterpriseServices; namespace Client.Chapter_10___COM_and_.NET_Interoperability { //Allows you to expose an object as a COM object public interface IObjCreator { void HelloWorld(); } //By inheriting from ServicedComponent, you allow this object to be //run in COM+ public class CObjCreator: ServicedComponent, IObjCreator { public void HelloWorld() { //Do something } } }