COM+ Component Services

FDN » COM/DCOM » COM+ Component Services

COM+ Component Services

COM+ (Component Services) extends COM with enterprise features: transactions, object pooling, role-based security, queued components, and events. It is the successor to MTS (Microsoft Transaction Server).

Key Features

FeatureDescription
Automatic TransactionsCOM+ enlists components in distributed transactions (DTC). Supports two-phase commit across databases and message queues.
Object PoolingReuse expensive objects instead of creating/destroying them per request. Configured per-component.
Just-in-Time ActivationObjects are activated only when a method is called, and deactivated after the call completes. Reduces resource usage.
Role-Based SecurityDefine roles (e.g., "Manager", "Clerk") and assign users. Check roles at the component, interface, or method level.
Queued ComponentsInvoke methods asynchronously via MSMQ. The call is queued and replayed on the server later.
Loosely Coupled EventsPublisher/subscriber event model decoupled from COM connection points.

Creating a COM+ Application

  1. Open Component Services (dcomcnfg).
  2. Expand Component ServicesComputersMy ComputerCOM+ Applications.
  3. Right-click COM+ ApplicationsNewApplication.
  4. Choose Create an empty application.
  5. Name it (e.g., "FlameNet Business Logic").
  6. Choose activation type:
    • Server application: Runs in its own dllhost.exe process (isolated, recommended for production)
    • Library application: Runs in the caller's process (faster, less isolation)
  7. Set the identity (user account) for server applications.

Adding Components

  1. Expand the new application → right-click ComponentsNewComponent.
  2. Choose Install new component(s) and browse to your DLL.
  3. Right-click the component → Properties to configure transactions, activation, and security.

Transaction Support

' VB6 COM+ Component with automatic transactions
' Set MTSTransactionMode = RequiresTransaction in class properties

Public Sub TransferFunds(ByVal lngFromAcct As Long, _
                         ByVal lngToAcct As Long, _
                         ByVal curAmount As Currency)
    Dim objCtx As ObjectContext
    Set objCtx = GetObjectContext()

    On Error GoTo ErrorHandler

    ' Debit source account
    DebitAccount lngFromAcct, curAmount

    ' Credit destination account
    CreditAccount lngToAcct, curAmount

    ' Commit the transaction
    objCtx.SetComplete
    Exit Sub

ErrorHandler:
    ' Abort the transaction
    objCtx.SetAbort
    Err.Raise Err.Number, "TransferFunds", Err.Description
End Sub

Role-Based Security Check

Public Sub ApproveExpense(ByVal lngExpenseID As Long)
    Dim objCtx As ObjectContext
    Set objCtx = GetObjectContext()

    If Not objCtx.IsCallerInRole("Manager") Then
        Err.Raise vbObjectError + 1, , "Access denied. Manager role required."
    End If

    ' ... approve the expense ...
    objCtx.SetComplete
End Sub
« Developer Network ‹ COM Automation with VBScript