|
Page 2 of 3
.
.
.
Using COM Components Directly
A COM component can be used in a .NET application by adding a reference to the project. In such situations, metadata is created from the type library of the component that is being referenced. When the object is instantiated in the .NET application, it is treated as any other .NET class library. The code acts and looks the same. Underneath the CLR is creating the RCW for the COM object and the COM object itself is marshaling calls back and forth between the managed and unmanaged process.
The ActiveX component which may be a .dll file will have to be registered with the Regsvr32.exe command. In the solution explorer of the project that is being used, reference to the .dll file will have to be added.
This component can be consumed like any other .NET component. However DLL created cannot be placed in a Global Assembly Cache and hence it cannot be reused.
Using COM+ Components
Developing components using COM specifications are of prime importance in COM+. COM+ enhances and upgrades the MTS services viz., Transaction Services, Security Services, and Synchronization Services: This also helps us develop simple development environment for Server Components. With COM+ user’s can:
1. Design single-user, single threaded components
2. Incorporates threading, concurrency, process management, and deployment.
3. Easily deploy your application as an n-tier application
4. Install the components by dragging and dropping
The various COM+ Services and the description are given below:
|
COM+ Services
|
Description
|
|
Resources Management
|
Manages resources such as database connection, network connection, and memory
|
|
Just-in-Time Activation
|
Conserves Server memory
|
|
Role-Based security
|
Validates security permissions based on roles
|
|
Concurrency
|
Enables multiple processes to run simultaneously
|
|
Object pooling
|
Provides a pool of readymade objects
|
|
Automatic Transaction management
|
Enables you to configure classes at the design stage, which take part in the transaction at run time
|
|
Queued components
|
Provides asynchronous message queuing
|
|
COM+ Events
|
Stores event information from different publishers
|
|
Shared property manager
|
Shares state among multiple objects within a server process
|
|
Compensating resource manager
|
Applies atomicity and durability properties to non-transactional resources
|
In visual studio create a new class project and add the following code to the class.
Imports System
Namespace ComPlusDemo
.
Public Class Class1
.......Public Sub check(ByVal years As Integer)
..............If years > 10 Then
.....................Console.WriteLine("Additional Incentive Payable!")
..............Else
.....................Console.WriteLine("No Incentive payable!")
..............End If
.......End Sub
End Class
End Namespace
After finishing this click the menu build and build the solution. The message Build Succeeded appears in the status bar. The class1 is created a component that accepts the number of years as an argument and returns a message so say if incentive is payable or not.
Now create a new VB project and select console application. Here we reference the class that was just created by right-clicking on the solution explorer and choosing the option Add Reference. In the module that is created add the following code.
Imports ComPlusDemo.ComPlusDemo
Namespace UseComp
.....Module Module1
.....
..........Sub Main()
...............' Uncomment the following line to set My.User to the currently logged on Windows user.
...............' My.User.InitializeWithWindowsUser
.
...............Dim years As Integer
...............Dim exp As String
...............Dim Eligibility As New Class1()
.....
...............Console.WriteLine("Enter the number of years!")
...............exp = Console.ReadLine()
...............years = Convert.ToInt16(exp)
...............Eligibility.check(years)
...............Console.ReadLine()
..........End Sub
.....
.....End Module
End Namespace
Now press F5 to execute the module, the result is shown below:

This demo shows the creation of .NET desktop console using components.
Creating Com+ Application:
From the Administrative tools choose component services. The component services window opens. Expand component services and MyComputer. Right click on the Com+ Application and choose new application as shown in the screenshot below:

This starts the wizard the first screen of which is shown below:

|