Results 1 to 5 of 5

Thread: Calling a class constructor from outside the application

  1. #1

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    Calling a class constructor from outside the application

    I have an ASP.NET (VB.NET) application, which has a class called clsSendEmail within it. I use this class from within the application to send a test email. What I want to do is create a console application, which will run completely independent of the web application, but is able to call the SendEmail class that is located within the Web app. How can I call the constructor of the SendMail class from outside the ASP.NET Application???

    Example
    VB Code:
    1. 'My ASP.NET Application
    2. Public Class clsSendMail
    3.     Public Sub New(ByVal strServerName As String, ByVal strDBName As String)
    4.         'Create a new instance of teh SendMail Class
    5.         Dim Mail As New SendMail(strServerName, strDBName)
    6.     End Sub
    7.  
    8.     Private Class SendMail()
    9.         'misc variable declarations
    10.  
    11.         Public Sub New(ByVal strServerName As String, ByVal strDBName As String, Optional ByVal blnTestEmail As Boolean = False, Optional ByVal strMailingID As String = "")
    12.  
    13.             'Do my email processing here, based on the parameters passed.
    14.         End Sub
    15.     End Class    
    16. End Class

    Here would be my console application that would be able to call the clsSendMail constructor
    VB Code:
    1. Public Class ConsoleSendMail
    2.    'What needs to be in this class to be able to call the
    3.    'clsSendMail class in the ASP.NET Application???
    4. End Class
    Last edited by Memnoch1207; Jan 1st, 2004 at 01:01 PM.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  2. #2
    Member
    Join Date
    Dec 2003
    Posts
    43
    You have me curious. If no one responds and you do figure it out please post your findings here.

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You are going to want to compile it as a seperate assembly, then insert it into the GAC (Global Assembly Cache). I think you will have to give permission to the asp.net app to use it after you do it. Then in your asp.net app, you are going to want to add a reference to the assembly, and work with it like any other external dll.

    The console app will need a reference to the dll also.

    I personally haven't done this, but it is well documented.

    http://msdn.microsoft.com/library/de...emblycache.asp

  4. #4

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    Here would be my assumption.

    The web application compiles to a .dll file (named appName.dll)

    I would then assume that within the console application, I would need to create an instance of this appName.dll, then call the clsSendMail constructor???

    Does anyone know if this is correct???
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You should be able to browse and reference the dll created for the ASP.NET app. Then just access the class you need.

    You could also use Late Binding and Reflection to get the class and use it as well but you would have to know the full path to the assembly that contains it and it would be slower than making a reference.

    PS: Making a reference will copy the dll to the application folder of the console app too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width