COM+ component services

COM+ component services

Please let other users know how useful this tip is by rating it below. Do you have a tip or code of your own you'd like to share? Submit it here.


Classes written using the Microsoft .NET Framework can make use of COM+ services in an integrated and logical manner. This article discusses COM+ services for in-process components such as JIT, synchronization, transactions, object pooling, constructor strings and the shared property group manager.

Today, developers use such tools as Microsoft Visual Studio 6.0 to build COM+ components and install the components in COM+ applications to use COM+ services. With Visual Studio.NET, managed classes are built and then installed in COM+ applications, in order to get such COM+ services as transactions, object pooling and activity semantics. Using Visual Studio.NET and the .NET Framework provides a number of advantages over Visual Studio 6.0 -- namely, better tools, the common language runtime and a much easier coding syntax. Each managed class can be hosted in a coexisting COM+ context; thus, managed classes can take full advantage of all the COM+ services. In the .NET Framework, these classes are known as serviced components. Any managed class can be modified to use COM+ services. The Microsoft.ComServices namespace provides various custom attributes and classes to assist the developer in accessing these services from managed code.

Creating

    Requires Free Membership to View

    When you register, you'll begin receiving targeted emails from my team of award-winning writers. Our goal is to provide a unique online resource for developers, architects and development managers tasked with building and maintaining enterprise applications using Visual Basic, C# and the Microsoft .NET platform.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchWinDevelopment.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchWinDevelopment.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

BankComponent.cs
using System;
using System.EnterprizeServices;
using System.Runtime.CompilerServices;
[assembly: ApplicationName("BankComponent")]
[assembly: AssemblyKeyFileAttribute("TestApp.snk")]
namespaceBankComponent
{ 
[Transaction(TransactionOption.Required)]
public class Account : ServicedComponent
{
// SetComplete automatically called if no exception
[AutoComplete]
public bool Post(int accountNum, double amount)
{
// .. update the database, no need to call SetComplete
return true;
}
}
// - Registration details -
// COM+ Application Name to add the Component

// Strong Name for Assembly

}

Creating BankConsoleClient.cs

using System;
using BankComponent;
namespace BankComponentConsoleClient
{
class Client
{
public static int Main()
{
Account act = new Account();
act.Post(5, 100);
return 0;
}
}
}

Compile the files with the following procedure

SN –k TestApp.snk
csc /target:library /r:Microsoft.ComServices.Dll BankComponent.cs
csc /target:exe /r:BankComponent.Dll BankConsoleClient.cs

When you invoke the BankConsoleClient.exe, the COM+ application gets generated. Now the component is ready to use the services of COM+ runtime and can be accessed using VB6.


This was first published in June 2003

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.