XP, Component Services and .NET

System.EnterpriseServices

Focusing on the new System.EnterpriseServices namespace, we will go through COM+ services accessible to .NET. In addition, we will focus on how attributes engage in recreation an important role. After that, we will generate a minimal serviced component. Than we will considerate the registering our simple with COM+.

The reason of the components and interfaces enclosed in System.EnterpriseServices is to provide access to COM+1.5 services from the .NET platform. This edition of the design is targeted for beta 2 of .NET on XP. The objective of System.EnterpriseServices for .NET beta 2 is to enable objects in .NET to make use of COM+ services and to participate in services with both managed and unmanaged objects. The first scenario is for two managed objects to participate in a transaction initiated from a managed client. In this case, both managed classes must be implemented as COM components. Further transactional attributes are added to the classes. Then the classes are registered in the COM+ catalog using the tool described in this document. A further scenario is using one managed object and one COM+ object within one transaction. This can be achieved in a similar way by implementing the managed object as a component and registering the managed component. Sample code for the first scenario is shown below and the process required deploying and running the components.

// -----------------------------------------------------------------
// ServicesApp.cpp
// -----------------------------------------------------------------

#using <mscorlib.dll>

using System;
using System::Runtime::InteropServices;
using System::EnterpriseServices;

//COM+ application name while it appears in the COM+ catalog
[assembly: ApplicationName(“TestServicesApp”)]
//Strong name used for assembly
[assembly: AssemblyKeyFileAttribute(“TestServicesApp.snk”)]

[Transaction]
public class Account : ServicedComponent
{
    [AutoComplete]
    void ATMDebit(int amount)
    {
        // Do a few more work, throw exception to terminate transaction
        // or else transaction commits
    }
}

class client
{
    static int main()
    {
        Account daccount = new Account();
        daccount.ATMDebit(100);
        return 0;
    }
}

What is New in System.EnterpriseServices?

Latest advance in .NET is the System.EnterpriseServices namespace. There we will come across the ServicedComponent class and the entire required attribute classes needed to create COM+ components. From creation to use there are four fundamental steps to COM+ component development. First, you need to inherit your class from ServicedComponent. Second, you have to apply attributes to your assembly, classes, and methods. Than third, you will strong name the assembly. Finally, you will register the component with COM+. Through .NET, you still have access to all the COM+ services available from COM+ 1.5. These COM+ services contain queued components, just in time activation, object construction, object pooling, automatic transaction processing, and some more.

System.EnterpriseServices Futures and Deployment

Additional to its enhanced and modern design, .NET is actually a fundamental component technology. Like COM, .NET supports with the means to fast and professionally build binary components, and Microsoft spends effort for .NET to create ultimately succeed COM. Unlike COM+, .NET does not provide its own component services. Instead, .NET relies on COM+ to make it available with instance management, transactions, activity-based synchronization, rough role-based security, disconnected asynchronous queued components, and loosely coupled events. The .NET namespace that contains the types necessary to use COM+ services was named System.EnterpriseServices to reflect the pivotal role it plays in building .NET enterprise applications.

While designing and developing a COM+ component, consider how you would adjust components in the Component Services snap. You will need to decide COM+ application name. You have to choose application activation type, server, or library. Will you use objects pooled or not? Do you use a construction string? Component configuration can (and sometimes must be) applied at design time, through attributes. These attributes are later read from the assembly’s metadata as the component is being registered. We will get to registration later. Important note is all attributes are optional, and if attributes are not applied defaults will be used for the registration process. The metadata level they pertain to, and the default value assigned to the COM+ catalog if the attribute is not applied. In some cases, attributes must work hand in hand with code implementation. This is still handy with .NET because a serviced component’s class constructor cannot accept arguments.

With Visual Studio.NET Beta2, assigning a strong name is easy. Go to the project explorer, right click the project name, and select Properties. Under the Common Properties folder, on the left, select Strong Name. Check the Generate strong name using: check box and then the Key file: option. Click the Generate Key button and you are all done. Now, we are ready to compile. After compile, we need register the component using COM+.

A simple .NET serviced component

namespace SimpleNamespace
{
    using System;
    using System::EnterpriseServices;
    using System::Windows::Forms; //for the MessageBox class

    public interface IMessage
    {
        void ShowMessage( );
    }
    /// <summary>
    /// .NET serviced component
    /// </summary>
    public class SimpleComponent:ServicedComponent,IMessage
    {
        SimpleComponent( ) {}//constructor
        void ShowMessage( )
        {
            MessageBox.Show("Hello!","SimpleComponent");
        }
    }
}

You might also like...

Comments

About the author

John Godel United States

John H. GODEL has an experience more than 22 years in the area of software development. He is a software engineer and architect. His interests include object-oriented and distributed computin...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”