ASP .NET Application vs. Windows Service

Discussion in 'ASP .Net' started by Untitled, Feb 9, 2005.

  1. Untitled

    Untitled Guest

    I have an ASP .NET web application that displays information. At the
    same time, i have a web service that collects information from various
    client applications. This data needs to be processed continuously in
    many ways and stored in the database. I need timers to poll the data
    and process on it and write to the database. I need to have lots of
    data cached as objects in memory as it is being used all the times. I
    need to generate weekly reports from data in the database.

    My question is this. Can I do this all in ASP .NET or do I need to have
    a windows service? Can i keep my web application alive and all the
    timers working? Has anyone done this before, actually used an ASP .NET
    Application in this way?

    Thanks

    Mark
    Untitled, Feb 9, 2005
    #1
    1. Advertising

  2. Untitled

    IPGrunt Guest

    "Untitled" <> confessed in news:1107989521.867262.17080
    @l41g2000cwc.googlegroups.com:

    > I have an ASP .NET web application that displays information. At the
    > same time, i have a web service that collects information from various
    > client applications. This data needs to be processed continuously in
    > many ways and stored in the database. I need timers to poll the data
    > and process on it and write to the database. I need to have lots of
    > data cached as objects in memory as it is being used all the times. I
    > need to generate weekly reports from data in the database.
    >
    > My question is this. Can I do this all in ASP .NET or do I need to have
    > a windows service? Can i keep my web application alive and all the
    > timers working? Has anyone done this before, actually used an ASP .NET
    > Application in this way?
    >
    > Thanks
    >
    > Mark
    >
    >


    You can do it either way.

    But, if as you describe, your data source supports webservice protocols (ie,
    SOAP), and there is to be no user interaction at the receiver, then you'd
    probably want to implement as a webservice.

    -- ipgrunt
    IPGrunt, Feb 9, 2005
    #2
    1. Advertising

  3. For important timed background tasks as you describe, a Windows Service is
    the best tool for the job. You might be able to coax ASP.NET into doing it,
    but it would be a bit like trying to fit a square peg into a round hole.

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net


    "Untitled" <> wrote in message
    news:...
    >I have an ASP .NET web application that displays information. At the
    > same time, i have a web service that collects information from various
    > client applications. This data needs to be processed continuously in
    > many ways and stored in the database. I need timers to poll the data
    > and process on it and write to the database. I need to have lots of
    > data cached as objects in memory as it is being used all the times. I
    > need to generate weekly reports from data in the database.
    >
    > My question is this. Can I do this all in ASP .NET or do I need to have
    > a windows service? Can i keep my web application alive and all the
    > timers working? Has anyone done this before, actually used an ASP .NET
    > Application in this way?
    >
    > Thanks
    >
    > Mark
    >
    Steve C. Orr [MVP, MCSD], Feb 9, 2005
    #3
  4. Untitled

    David Browne Guest

    "Steve C. Orr [MVP, MCSD]" <> wrote in message
    news:ex%...
    > For important timed background tasks as you describe, a Windows Service is
    > the best tool for the job. You might be able to coax ASP.NET into doing
    > it, but it would be a bit like trying to fit a square peg into a round
    > hole.
    >


    I wish there was an easy way to do this in IIS, since it forces you to
    either run your code in two processes or use remoting.

    If you web site is doesn't need the security and other services of IIS you
    could host ASP.NET inside your service. Currently you must also supply an
    HTTP server, but you can download Cassini for this. Just add a reference in
    your service to Cassini.dll and start a server an unused port of your
    choice.

    http://www.asp.net/Projects/Cassini/Download/Default.aspx?tabindex=0&tabid=1

    In .NET 2.0 you will be able to use the same HTTP server stack that IIS uses
    in a process of your choice. So you will have all the performance and
    security of IIS, without having to run your application under IIS.

    http://msdn.microsoft.com/msdnmag/issues/04/12/ServiceStation/default.aspx



    David
    David Browne, Feb 10, 2005
    #4
  5. Untitled

    Untitled Guest

    Thanks David, that was a very good post. Cassini seems like a good idea
    untill .NET 2.0.

    However, the ideal choice for development, performance and security
    remains to do everything in the ASP .NET Web Application. I need to get
    some information concerning that. I know it is possible because I have
    tried it, but only for a short period of time. I simply need some sort
    of documentation concerning this that would help me make a descision;
    maybe an MSDN article that would compare Windows Services to Web
    Applications. Or maybe an an article by someone who has done this
    before.

    Thanks guys
    Untitled, Feb 10, 2005
    #5
  6. Untitled

    David Browne Guest

    "Untitled" <> wrote in message
    news:...
    > Thanks David, that was a very good post. Cassini seems like a good idea
    > untill .NET 2.0.
    >
    > However, the ideal choice for development, performance and security
    > remains to do everything in the ASP .NET Web Application. I need to get
    > some information concerning that. I know it is possible because I have
    > tried it, but only for a short period of time. I simply need some sort
    > of documentation concerning this that would help me make a descision;
    > maybe an MSDN article that would compare Windows Services to Web
    > Applications. Or maybe an an article by someone who has done this
    > before.
    >


    The problem is that the ASP.NET process model doesn't really support this.
    Your application is not started automatically when IIS is started. It only
    starts when the first HTTP request is made. So you must have a mechanism
    to "tickle" your application every time IIS restarts. Furthermore you must
    make sure that IIS never recycles your application, which it may do on
    regular intervals or on reaching certian memory thresholds.

    David
    David Browne, Feb 10, 2005
    #6
  7. Untitled

    Untitled Guest

    Another question comes to mind from the Cassini post by David. Even if
    I did use Cassini. How would I host ASP .NET inside my Windows Service?
    ASP .NET runs under its own service.

    Mark
    Untitled, Feb 10, 2005
    #7
  8. Untitled

    Untitled Guest

    I am aware of these problems and I do have a "tickling" system that
    should garantee both those things.

    I'm looking for other potential problems, or live examples of this in
    action. Our company cannot take such a blind risk. Strangely enough i
    have found NO documentation or articles ANYWHERE concerning this.

    ASP .NET does have timers. It is possible to start your own threads in
    ASP .NET. Everything I want to do seems possible.

    The only question is "Can I really do all these things in ASP .NET and
    expect it to work just the same? Or is there something i'm unaware of?
    Is there something else that is different between a Windows Service and
    an ASP .NET Web Application that i do not know about"

    Thanks Guys you have been really helpful

    Mark
    Untitled, Feb 10, 2005
    #8
  9. > The only question is "Can I really do all these things in ASP .NET and
    > expect it to work just the same? Or is there something i'm unaware of?
    > Is there something else that is different between a Windows Service and
    > an ASP .NET Web Application that i do not know about"


    You can hammer a nail with a screwdriver, but it's a lot harder to do.
    You're describing a Service, regardless of what tools you used to build it.
    It should be built as a Service.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Neither a follower nor a lender be.

    "Untitled" <> wrote in message
    news:...
    >I am aware of these problems and I do have a "tickling" system that
    > should garantee both those things.
    >
    > I'm looking for other potential problems, or live examples of this in
    > action. Our company cannot take such a blind risk. Strangely enough i
    > have found NO documentation or articles ANYWHERE concerning this.
    >
    > ASP .NET does have timers. It is possible to start your own threads in
    > ASP .NET. Everything I want to do seems possible.
    >
    > The only question is "Can I really do all these things in ASP .NET and
    > expect it to work just the same? Or is there something i'm unaware of?
    > Is there something else that is different between a Windows Service and
    > an ASP .NET Web Application that i do not know about"
    >
    > Thanks Guys you have been really helpful
    >
    > Mark
    >
    Kevin Spencer, Feb 10, 2005
    #9
  10. Untitled

    Untitled Guest

    Well its not just a Service. It's also a Web Service and a Web
    application. I need to somehow have all three in one.

    Either i'm able to make my Service a Web Service and a Web application,
    maybe using Cassini as David described. Or i'm able to make my Web
    application a Service as i'm suggesting.
    Untitled, Feb 10, 2005
    #10
  11. Untitled

    David Browne Guest

    "Untitled" <> wrote in message
    news:...
    > Another question comes to mind from the Cassini post by David. Even if
    > I did use Cassini. How would I host ASP .NET inside my Windows Service?
    > ASP .NET runs under its own service.
    >


    Cassini.dll allows you to host ASP.NET in your own service. You could not
    run the Cassini web server on the same port as IIS, of course.

    Here's a discussion of hosting Cassini.dll in a windows service:

    http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=560232

    David
    David Browne, Feb 10, 2005
    #11
  12. A Swiss army knife has quite a few tools in the same package. However, the
    nail clippers are not good for carving.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Neither a follower nor a lender be.

    "Untitled" <> wrote in message
    news:...
    > Well its not just a Service. It's also a Web Service and a Web
    > application. I need to somehow have all three in one.
    >
    > Either i'm able to make my Service a Web Service and a Web application,
    > maybe using Cassini as David described. Or i'm able to make my Web
    > application a Service as i'm suggesting.
    >
    Kevin Spencer, Feb 10, 2005
    #12
  13. Untitled

    Untitled Guest

    I read the posts. I understand how it is done. But I don't see anything
    about NOT having the ASP .NET process run on its own. It still has to
    be its own process running under its own memory space. This means I
    cannot share objects with the Windows Service except through remoting.
    This in turn means, when the ASP .NET recieves thousands of datasets
    from my clien applications they have to be serialized again to be sent
    to the Windows Service (because the windows service is the one doing
    all the work). This also means whenever the user makes changes to data,
    the changes have to go through remoting to my windows service and then
    to the database. And finally, this also means that though I have lots
    of data loaded in memory on my windows service, my ASP .NET Web
    application still has to query the data from the database, or through
    more remoting calls.

    These are the things i'm trying to avoid.

    Thanks again guys, I really apreciate it

    Mark
    Untitled, Feb 10, 2005
    #13
  14. Untitled

    David Browne Guest

    "Untitled" <> wrote in message
    news:...
    >I read the posts. I understand how it is done. But I don't see anything
    > about NOT having the ASP .NET process run on its own.


    If you write your own windows service and reference the cassini.dll, as
    described in that post, ASP.NET will be running in your service process.
    You will be able to share objects between ASP.NET and your service. The
    only wrinkle is that ASP.NET will be hosted in a seperate AppDomain. You
    can modify the cassini code to return your main service class a reference to
    the created AppDomain and start the rest of your service code in that
    AppDomain too. Then you won't have to marshal between the AppDomains.

    Just add the following method to Cassini.Host.cs

    public System.AppDomain GetDomain()
    {
    //Host is MarshalByRef and lives in the web app's AppDomain
    //so this call is marshalled and run on a thread in the other AppDomain
    return Thread.GetDomain();
    }

    And this to Cassini.Server.cs

    public Host GetHost()
    {
    return _host;
    }


    Then you can get the AppDomain for your web application with

    Server.GetHost().GetDomain()

    And you can fire up your service types over there.

    David

    David
    David Browne, Feb 10, 2005
    #14
  15. Untitled

    Untitled Guest

    Apparently, even though I have access to the Domain i don't think i can
    access its contents.

    "Code running in one application cannot directly access code or
    resources from another application. The common language runtime
    enforces this isolation by preventing direct calls between objects in
    different application domains. Objects that pass between domains are
    either copied or accessed by proxy."

    <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconapplicationdomainsoverview.asp>
    Untitled, Feb 10, 2005
    #15
  16. Untitled

    David Browne Guest

    "Untitled" <> wrote in message
    news:...
    > Apparently, even though I have access to the Domain i don't think i can
    > access its contents.
    >
    > "Code running in one application cannot directly access code or
    > resources from another application. The common language runtime
    > enforces this isolation by preventing direct calls between objects in
    > different application domains. Objects that pass between domains are
    > either copied or accessed by proxy."
    >
    > <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconapplicationdomainsoverview.asp>
    >


    Right, but with a reference to an AppDomain you can create an instance of
    any MarshalByRef object in the AppDomain using
    AppDomain.CreateInstanceAndUnwrap.

    You would implement your main service class as a MarshalByRef object, put a
    single .Run method on it, create it using AppDomain.CreateInstanceAndUnwrap,
    and the hit Run. It will run in the target AppDomain.

    http://msdn.microsoft.com/library/d...ppdomainclasscreateinstanceandunwraptopic.asp

    David
    David Browne, Feb 10, 2005
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick
    Replies:
    2
    Views:
    651
    Steven Cheng[MSFT]
    Oct 1, 2004
  2. =?Utf-8?B?c2h5YW0=?=
    Replies:
    2
    Views:
    701
    =?Utf-8?B?c2h5YW0=?=
    May 22, 2006
  3. DNB
    Replies:
    1
    Views:
    254
  4. Peter Stojkovic
    Replies:
    0
    Views:
    475
    Peter Stojkovic
    Mar 30, 2006
  5. DNB
    Replies:
    1
    Views:
    307
    John Saunders [MVP]
    Jan 20, 2008
Loading...

Share This Page