Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

Implementing ESC (Enterprise Services Components) in .net 2.0 (second Part)

Author: Zunnair

In this article I will explain the way in which we can create the Enterprise Services Components. Enterprise . Now I will explain the product class This is the part Two.

There are two classes, Supplier and Product, that form the basis for the components in this application. Source code is given with that article. So for proper understanding Follow the instructions below.

1-Create a Product class from add new Components.

Construct method applies only when the component is part of a

COM+ application. This method gets called right after the constructor. The constructString parameter contains the class's default property, which was set above in the ConstructionEnabledAttribute. The default string appears in the COM+ Explorer, in the Object construction section of the Activation Tab of your component's properties. So a System


Administrator can adjust its value without your having to recompile your class. In this example, we've set it to a connection string, but it could contain any string value you choose.



Protected Overrides Sub Construct(ByVal constructString As String)

        If constructString.Length > 0 Then

            m_strConnectionString = constructString

        End If

    End Sub

2-This Function Simulates a call to a stored procedure to add a supplier to the Suppliers table. AutoComplete attribute means if the procedure exits with no exception, then SetComplete is automatically called, otherwise SetAbort is called.


<AutoCompleteAttribute(True)> _

Public Sub AddProduct(ByVal ProductName As String, ByVal SupplierID As Integer, ByVal UnitPrice As Decimal)



DoTracing("Product.AddProduct called at " & DateTime.Now.ToLongTimeString)

        Catch exp As Exception

            Throw New Exception(exp.Message, exp.InnerException)

        End Try

    End Sub

3-this function Indicate to COM+ whether the object can be pooled.

Put code here to indicate whether or not you want the object to

be pooled at this time.



Protected Overrides Function CanBePooled() As Boolean

DoTracing("Product.CanBePooled called at " & DateTime.Now.ToLongTimeString)

        Return True

 End Function

 4-Reports on current object status in various ways.Create a trace listener for the event log. Dim logTraceListener As New EventLogTraceListener("Product--VB.NET How-To: EnterpriseComponents")

Add the trace listener to the collection. Trace.Listeners.Add(logTraceListener)Create a trace listener that will send send trace output to the consoleIt could have written to a file or stream instead. Add the trace listener to the collection. Write output.



Private Sub DoTracing(ByVal strMsg As String)

        Dim consoleTraceListener As New TextWriterTraceListener(System.Console.Out)




    End Sub

On the data input form you can add a supplier, by entering a Company Name and Phone and clicking Add Supplier. To update, enter a Company Name, Phone and ID. To delete a supplier, only an ID is needed. If the operation is successful, a message on the status line will indicate that. Working with products is similar.
Note that no database access is performed.  This How-To is focused on illustrating COM+ features.

Each class writes to the Output Window when various events occur, such as instantiation, activation, and deactivation. See the DoTracing procedure in each class. You can uncomment the lines that make it also write to the Event Log. Review these entries to track the life cycle of the components.

Set breakpoints at various places in the classes to see the sequence of events as an object is used in the Enterprise Services environment

Add Article Comment:
Name :
Email Address :
Comments :
<< Implementing ESC (Enterprise Services Components) in .net 2.0 (First Part)

Disclaimer - Privacy
© 2002-2017