none
Stop a background WCF Service when application is stopped from IIS 7.0 RRS feed

  • Question

  • My web application has multiple WCF services in it. Each service has been created in different VS project and hence mapped to different virtual directory on IIS (under same web application)

    e.g 

    localhost

    ---/ServiceOne

    ---/ServiceTwo

    ---/ServiceThree

    One and Two service creates a background thread and monitors changes in database and accordingly performs some task. ServiceThree is an accessible from outside world and provides data to the database which serivceOne and ServiceTwo process. (We needed a common place to monitor and manage the services so hosted all of them on IIS instead of hosting the background services on Windows hosting environment).

    There are four application pools. One for the complete web application, and one each for the three services.

    Problems:

    1. The Service stop when application pool is stopped. (perfect). Things go out of hand when we stop the background services directly from IIS. Both the service continue to process the data from database. 
    2. Now if the service is started again another instance of service host is created and that too in random app pool, so if I stop the parent app pool of the service, it appears that the service is still processing the data from database.

    Is there any way to determine when application is stopped and stop its services working in background. I have read that when a service is stopped from IIS it stops forwarding new requests to the service but if it had already started processing a request then it will finish it.

    similar question.

    Friday, July 19, 2013 12:24 PM

Answers

  • For WCF services monitoring you can leverage Windows Server AppFabric. Windows Server AppFabric provides streamlined hosting and monitoring capabilities that support composition scenarios, it is an extension of the Application server role on the Microsoft Platform.

    For background services, probably you may check from IIS Worked Processes you can view information about worker processes running on the Web server and about request running inside those worker processes.

    Friday, July 19, 2013 1:40 PM