Maintain global state across all requests in a wcf application hosted in IIS RRS feed

  • Question

  • I need to maintain some state in a stateless wcf service hosted in IIS.  Basically, it's a restful service that accepts http posts, then formats the data and sends it off to another web service.  When that other web service is down, and the data is unable to be sent, I'd like to queue up the data until a later time when the web service is back online.  When it's back online, I'd like to loop through the queued data and send.  How can I store a queue that will persist across the life of the application?  Would a static class/static variable of concurrentqueue suffice?
    Tuesday, April 23, 2013 6:49 PM


  • Hello Pork Chop,

    I don't think anything stored in the application pool would be a good idea.  You want to have a more persistent repository.  This is because you don't have 100% control of IIS.  You can configure the application pool to not shutdown after activity or to not restart on a schedule but what about other factors outside your control (e.g., maintenance restart)? 

    Assuming there is not an existing system that could provide this type of persistence (e.g., BizTalk), I would use either MSMQ or SQL Server (or even using a file folder as a queue).  Yes, this introduces some new technologies and complexity and there will be some overhead.  In most circumstances, the overhead of introduce persistence is minimal compared to the overhead caused by using webservice calls so this should not be an issue.

    Also, if this is a multi-server solution and order is important; you might run into additional issues by introducing a queue.

    Hope this gives you some things to think about.


    Tuesday, April 23, 2013 10:36 PM