Click here to Skip to main content
13,045,657 members (68,784 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 1 Nov 2009

My First COM+ Serviced Component

, 1 Nov 2009
Rate this:
Please Sign up or sign in to vote.
Just sharing my experience from six years ago, in 2003, when I was working as a developer.


In this Internet world of connected network applications, it is reasonable to expect that your Web applications scale to meet the needs of millions of users who will access your Web site. COM+ is a core element in the Windows DNA 2000 methodology to create scalable, extensible, and maintainable distributed applications. However, in the .NET world, COM+ components are referred to as serviced components. Due to the number of changes in the .NET strategy, the deployment model for serviced components is different from deploying traditional COM+ components. In this article, we will understand how to deploy serviced components using the various tools provided by the .NET Framework. Along the way, we will also highlight how the deployment model varies for different types of serviced components. Finally, we will wrap it up by understanding how the deployment of serviced components can be automated using a Windows installer project.

Component services in Windows 2000 has a wealth of enterprise functionality that provides all the plumbing required for creating distributed, Web-enabled applications. Although COM+ services were originally designed for use with COM components, it would be nice if .NET components could also use them because of services such as object pooling, database connection pooling, sharing resources, role based security, and distributed transaction processing monitoring that the COM+ runtime provides.

In the .NET Framework, there is a separate namespace called System.EnterpriseServices that contains all the classes required for providing COM+ services to applications. For an introduction to COM+, please take a look at the following link from TechNet: Introduction to COM and COM+.

The Problem

We have a web server that hosts a number of different applications, classic ASP websites, ASP.NET applications, and console applications scheduled in MS-Tasks. All of these applications use our SMTP server to send emails. Our SMTP server requires user authentication. We have a single email account dedicated for our web to be used as a sender email ID from all our applications.

Imagine that your development manager asked you to change that email account password for security reasons and he has a plan for changing it frequently every month. It is really a pain to go through all your .NET application web.config files and change the email setting and all your classic ASP websites also to change the include files.

The Solution

I am sure there are so many solutions now to overcome the problem mentioned above, but here I am just sharing my experience from six years ago, in 2003, when I was working as a developer in a software development company. At that time, I had very good experience working in Classic ASP, but only two years experience working in .NET. And we were using MS VS2003 and coding in VB.NET. I was not very familiar with C# :)

The first thing I thought about was to do a global DLL file which would read a single config file located in our web server; this DLL file could be used in any application, whether it is a classic ASP, .NET, or Java application.

I utilize the COM+ serviced component to develop a class library that has a public function for sending emails. The email setting would be read from an XML config file located in the web server.

Using the Code

Here I am going to explain my solution step-by-step (in VS2005):

  • In VS2005, create a Class Library project.
  • Add a reference to the System.EnterpriceServices DLL.
  • 01.jpg

    You will need to add the following line in the Imports section:

    Imports System.EnterpriseServices
  • You have to make your class inherit from the “ServicedComponent” class:
  • Public Class btnmail
       Inherits EnterpriseServices.ServicedComponent
  • I then create just a simple function (HelloWorld) for testing purposes only:
  • ' Shows Explicit SetComplete/SetAbort.
    Public Function HellowWorld() As String
        Return "Hello World"
    End Function
  • This is the email function that is used to send emails:
  • Public Function SendEmail(ByVal sender, ByVal sname, ByVal recipient, _
                    ByVal cc, ByVal subject, ByVal body) As Boolean
        Dim retVal As Boolean = False
            'defining dataset 
            Dim ds As DataSet = New DataSet()
            'reading email setting config file. 
            'here i am hard-coding the location of the config.xml file.
            'refer to the source code to see the config file structure.
            ' assigning the values to the vars.
            Dim smtpserver As String = ds.Tables(0).Rows(0)("ServerName")
            Dim UserName As String = ds.Tables(0).Rows(0)("UserName")
            Dim Password As String = ds.Tables(0).Rows(0)("Password")
            Dim bcc As String = ds.Tables(0).Rows(0)("BCC")
            ' creating email message object
            Dim message As New MailMessage()
            message.IsBodyHtml = True
            message.From = New MailAddress(sender, sname)
            If Not String.IsNullOrEmpty(cc) Then
            End If
            If Not String.IsNullOrEmpty(bcc) Then
            End If
            message.Subject = subject
            message.Body = body
            Dim emailClient As New SmtpClient(smtpserver)
            'check to see if there are user name and password,
            ' then only i am doing the authentication part.
            If Not String.IsNullOrEmpty(UserName) And _
               Not String.IsNullOrEmpty(Password) Then
                Dim SMTPUserInfo As New _
                    System.Net.NetworkCredential(UserName, Password)
                emailClient.UseDefaultCredentials = False
                emailClient.Credentials = SMTPUserInfo
            End If
            retVal = True
        Catch ex As Exception
            'logging the error to a log file if there is any.
            Dim sw As StreamWriter = _
                New StreamWriter("d:\smtpmailsetting\logs\" & _
                Now.ToString("ddMMyyyy-hhmmss") & ".log", True)
            Catch ex1 As Exception
            End Try
            retVal = False
        End Try
        Return retVal
    End Function
  • Then, we will create a key file using the sn utility. To generate the key file, we will run the Visual Studio .NET command prompt and then enter the command as shown below:
  • sn -k btnmail.snk


  • Copy “testkey.snk” to your project solution.
  • Add “AssemblyInfo.vb” and add the key info:
  • <Assembly: AssemblyTitle("")> 
    <Assembly: AssemblyCompany("")>
    <Assembly: AssemblyProduct("")> 
    <Assembly: AssemblyCopyright("")>
    <Assembly: AssemblyTrademark("")> 
    <Assembly: CLSCompliant(True)>
    <Assembly: AssemblyKeyFile("..\..\btnmail.snk")>
  • Now we need to install it in the Global Assembly Cache, “GAC”.
  • regsvcs (path of the dll)
  • Create a vbs file to test it. Create “test.vbs” which contains the following code:
  • set obj = CreateObject("smtpbtnmail.btnmail")
  • Double click on it to run it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Architect Gulf air - Bahrain
Bahrain Bahrain
Current Position is : Information System Analyst

Leading a Team of Developers for developing ecommerce websites and systems integration using several integration methods such as XML.

Manage ISP infrastructure, web servers, database servers, application servers, email servers and networks. Design the architecture of complex web applications; build web applications in JAVA, asp, asp.Net; manage web sites including networking and database; experienced in MS Sql Server and Oracle;

stay current with emerging trends and technological advances in the industry.

MCTS,MCAD VB.NET, ASP.NET and XML Services,BTEC National Diploma in Computer Studies.

You may also be interested in...


Comments and Discussions

General[comments] Pin
Member 823782330-Jul-13 0:21
memberMember 823782330-Jul-13 0:21 
QuestionExcellent Pin
Musthafa (Member 379898)29-Oct-12 21:40
memberMusthafa (Member 379898)29-Oct-12 21:40 
Questionmy vote of 5 Pin
muhamad yousef28-May-12 20:24
membermuhamad yousef28-May-12 20:24 
GeneralMy vote of 2 Pin
gaurav_verma_mca1-Nov-09 3:36
membergaurav_verma_mca1-Nov-09 3:36 
GeneralRe: My vote of 2 Pin
hussain.attiya1-Nov-09 20:33
memberhussain.attiya1-Nov-09 20:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 1 Nov 2009
Article Copyright 2009 by hussain.attiya
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid