Results 1 to 9 of 9

Thread: ASP.net dll as a service

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Manchester, England, UK
    Posts
    247

    ASP.net dll as a service

    I have a really simple web app with has some basic user interactions and a background process.

    At the minute I set up a timer on application start and use a background working all within the web app.

    This works, but obviously has limitations.

    Because the project is very simple and I don;t want to over complicate the structure as an interim step I would like to do is make the same asp.net dll capable of running as a service. i.e. the dll from the asp.net web app

    Can I just add the standard constructs (eg below) and this will work or do I need to do something more?

    Code:
    Public Class Service1
    
        Protected Overrides Sub OnStart(ByVal args() As String)
            ' Add code here to start your service. This method should set things
            ' in motion so your service can do its work.
        End Sub
    
        Protected Overrides Sub OnStop()
            ' Add code here to perform any tear-down necessary to stop your service.
        End Sub
    
    End Class

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: ASP.net dll as a service

    It depends what you want to achieve.P.E. update the same database asp.net uses.
    But i'm curious on what exactly you want to do with a standard service and asp.net.
    It's not the same as a web service if you are thinking something like that.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: ASP.net dll as a service

    Hello,

    What you have described is a Windows Service, which once installed on your machine, is always running.

    An ASP.Net Service is not "always running", however, it can be accessed when requested, on a polling basis. This poll would need to be initiated from the client machine, which some form of JavaScript.

    This would allow you to "mimic" the functionality of a Windows Service, although, this solution is far from perfect.

    I think sapator is right. If you can let us know exactly what you are trying to achieve, we can try to guide you in the right direction.

    Gary

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Manchester, England, UK
    Posts
    247

    Re: ASP.net dll as a service

    Sorry you might have missed the point....I know the differences and I know what I am doing is less than ideal.
    so as an interim step rather than deconstruct the app I want to expose the existing ASP.net dll (class) as a service.

    So the question is , can this be done, and if so what else do I need to do apart from the code I posted?

    As an aside if I run it as a windows service can I still use the same threadpool?

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: ASP.net dll as a service

    Okay, so let me see if I have this right...

    You want to take the compiled dll from your ASP.Net application, which has a number of methods, properties, etc, that you want to expose in a Windows Service. Is that right?

    You are likely going to struggle to do this, as the compiled dll will have a number of ASP.Net dependencies, that will not exist in the Windows Service. You would need to abstract the common methods etc into a standalone DLL, that has no dependencies on ASP.Net. Once you have that, you could use that dll within both the windows service, and the ASP.Net application.

    In terms of sharing the same threadpool, I am not sure on that one.

    Gary

  6. #6
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: ASP.net dll as a service

    As it is known, services run on their own threadpool. You will need to use threading to combine if possible the two of them.
    Personally i have managed to do so in the past with the help of JMC but it's ok for a simple app but probably i horror for what you are trying.
    Anyhow i haven't exactly understood what you are trying but something inside me is repeating "wrong in so many ways,wrong in so many ways,wrong in so many ways,wrong in so many ways"
    Maybe a full explanation on what you want will help for an alternative?
    You write "Because the project is very simple and I don;t want to over complicate the structure as an interim step", but you are obviously overcomplicated thinks, doing something that is not meant to be done.
    Anyway good luck in whatever way you decide to go.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Manchester, England, UK
    Posts
    247

    Re: ASP.net dll as a service

    Ok so the alternative I have come up with is to migrate the app to another server on iis 7.5 and make use of
    startMode="AlwaysRunning"
    serviceAutoStartEnabled="true"
    serviceAutoStartProvider="InitBackground"

    However this gives me an error :

    There was an error during processing of the managed application service auto-start for configuration path: 'MACHINE/WEBROOT/APPHOST/XmlGen/'. The error message returned is: 'An error occurred while executing Preload method.

    Exception: System.InvalidOperationException

    Message: An error occurred while trying to create preload provider 'Business.BackgroundStartup, Business'.

    Exception: System.IO.FileNotFoundException


    Namespace Business

    Public Class BackgroundStartup
    Implements System.Web.Hosting.IProcessHostPreloadClient

    Public Sub Preload(parameters() As String) Implements System.Web.Hosting.IProcessHostPreloadClient.Preload
    ' Business.ServiceThreads.Start()
    ServiceThreads.WriteLog("Preload ")
    End Sub
    End Class

    <site name="Xml" id="3" serverAutoStart="true">
    <application path="/" applicationPool="xml">
    <virtualDirectory path="/" physicalPath="C:\home\clients\db\xml\htdocs" />
    </application>
    <bindings>
    <binding protocol="http" bindingInformation="*:80:localhost" />
    </bindings>
    <applicationDefaults serviceAutoStartEnabled="true" serviceAutoStartProvider="InitBackground" />

    </site>

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Manchester, England, UK
    Posts
    247

    Re: ASP.net dll as a service

    I've resolved it. Fairly obvious on reflection ....

    App_global.asax.vkpfe1jl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

    System.IO.FileNotFoundException

    I hadn't pre-compiled on the testing server therefore the assembly name was not fixed. Added a web deployment project and pre-compiled to testing and it works.

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: ASP.net dll as a service

    Glad to hear that you got it working!

    Gary

Tags for this Thread

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