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
| Feature | Description |
|---|---|
| Automatic Transactions | COM+ enlists components in distributed transactions (DTC). Supports two-phase commit across databases and message queues. |
| Object Pooling | Reuse expensive objects instead of creating/destroying them per request. Configured per-component. |
| Just-in-Time Activation | Objects are activated only when a method is called, and deactivated after the call completes. Reduces resource usage. |
| Role-Based Security | Define roles (e.g., "Manager", "Clerk") and assign users. Check roles at the component, interface, or method level. |
| Queued Components | Invoke methods asynchronously via MSMQ. The call is queued and replayed on the server later. |
| Loosely Coupled Events | Publisher/subscriber event model decoupled from COM connection points. |
Creating a COM+ Application
- Open Component Services (
dcomcnfg). - Expand Component Services → Computers → My Computer → COM+ Applications.
- Right-click COM+ Applications → New → Application.
- Choose Create an empty application.
- Name it (e.g., "FlameNet Business Logic").
- Choose activation type:
- Server application: Runs in its own
dllhost.exeprocess (isolated, recommended for production) - Library application: Runs in the caller's process (faster, less isolation)
- Server application: Runs in its own
- Set the identity (user account) for server applications.
Adding Components
- Expand the new application → right-click Components → New → Component.
- Choose Install new component(s) and browse to your DLL.
- 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