2. Enterprise Services
Provides support for
Distributed Transactions
Security
Object Pooling
Just in time activation
Queued Components
Loosely Coupled Events
Server Application Process Model
3. Enterprise Services
The .NET Enterprise Services are today a
wrapper around the COM+ Service
Are a strategic part of .NET
In .NET, those types are know under the
name
.NET Enterprise Services
4. Transaction Service
Transaction is a unit of work in which a series of
operations occur.
COM+ uses programmatic transactions to ensure
that resources are not permanently updated unless
all operations within the transaction complete
successfully.
6. Transaction Service (Example)
<TransactionAttribute(TransactionOption.Required)> _
Public Class TransferService
Inherits ServicedComponent
Public Function transfer(ByVal ConnString1 As String, _
ByVal ConnString2 As String, _
ByVal Account1 As String, ByVal Account2 As String, _
ByVal AmountToTransfer As Integer) As Boolean
Dim RetValue As Boolean
Dim objCredit As New BankOne
Dim objCharge As New BankTwo
Try
objCredit.credit(ConnString2, Account2, AmountToTransfer)
objCharge.charge(ConnString1, Account1, AmountToTransfer)
RetValue = True
ContextUtil.SetComplete()
Catch exc As Exception
ContextUtil.SetAbort()
. . .
End Try
End Function
End Class
7. Transaction Service (Example)
<TransactionAttribute(TransactionOption.Required)> _
Public Class BankOne
Inherits ServicedComponent
Public Sub charge(ByVal ConnString As String, _
ByVal Account As String, ByVal AmountToCharge As Integer)
Dim strSQL As String
strSQL = "UPDATE Accounts SET … WHERE Description = '" & Account & "'“
Dim RowsUpdated As Integer
Dim cnn As New SqlConnection(ConnString)
Dim cmd As New SqlCommand(strSQL, cnn)
Try
cnn.Open()
RowsUpdated = cmd.ExecuteNonQuery()
If RowsUpdated = 1 Then
ContextUtil.SetComplete()
Exit Sub
Else ' UPDATE failed
ContextUtil.SetAbort()
Throw New Exception("Invalid account or insufficient money.")
End If
Catch exc As Exception
ContextUtil.SetAbort()
. . .
End Try
End Sub
End Class
8. Transaction Service (Example)
<TransactionAttribute(TransactionOption.Required)> _
Public Class BankTwo
Inherits ServicedComponent
Public Sub credit(ByVal ConnString As String, _
ByVal Account As String, ByVal AmountToCredit As Integer)
Dim strSQL As String
strSQL = "UPDATE Accounts SET … WHERE Description = '" & Account & "'"
Dim RowsUpdated As Integer ' Number of modified rows
Dim cnn As New SqlConnection(ConnString)
Dim cmd As New SqlCommand(strSQL, cnn)
Try
cnn.Open()
RowsUpdated = cmd.ExecuteNonQuery()
If RowsUpdated = 1 Then
ContextUtil.SetComplete()
Exit Sub
Else
' UPDATE failed
ContextUtil.SetAbort()
Throw New Exception("Invalid account.")
End If
Catch exc As Exception
ContextUtil.SetAbort()
. . .
End Try
End Sub
End Class
10. Queued Components
Queued components provide for an easy
implementation of asynchronous (as well as
disconnected) method calls, where the client
does not have to wait until the method call
finishes.
The Queued component architecture in
COM+ internally uses the MSMQ queues to
deliver the messages (method calls) to a
COM+ component.
The transmitted message is stored in the
queue and attempted for delivery when the
receiving component’s machine becomes
available.
11. Queued Components (Cont’d.)
Server
Client MSMQ Queue
QC Recorder (COM Queued Component
component) MSMQ Queue Listener
MSMQ Queue Queued Component
Player (COM comp.)
COM Object
14. Queued Components (Implementation)
Imports System.Messaging
. . .
Private Sub Send()
Dim myQueue As MessageQueue
Try
' connect to the queue and send the message
myQueue = New MessageQueue(".private$DevXTestQueue”)
myQueue.Send("Test Message”)
Catch ex As Exception
MessageBox.Show("Exception was thrown: " & ex.Source & ": " &
ex.Message)
End Try
End Sub