WCF with Msmq

How to resolve MSMQ WCF issue for service deactivation

I am sure if you are using WCF with MSMQ and hosting it on IIS (Follow this to Setup MSMQ with WCF using Net.Msmq binding), you would have faced the issue of
services getting deactivated as soon as app pool is recycled or the service is idle for long. This is due to WAS process getting inactive. It creates a big enterprise problem. Once deactivated, the services do not auto activate itself even if there are messages pending on the queue to be processed.

Now, there are multiple solutions to this.

1. Host WCF service as a managed windows service. This ensures the service is active at all the times.

2. If you want to host the service as part of IIS, you would constantly need to ping the service after a specified interval of time. For this, create a Ping operation in your service. We will call this by scheduling a windows service.

Ping

Now,

  • Create a windows service application.
  • Override the OnStart event to schedule the service using the Timer Class.
    This will schedule the service to be executed every 60 seconds (60000 ms).On Start
  • Here, we have attached time_Tick event to the Elapse event handler. This is the event that will be triggered every 60 seconds.
  • In this event, call the Ping service operation and log the result. This will ensure the
    service is kept active & does not go down even if the app pool is recycled or there are no messages on the queue for long.timer tick
  • Now, install this service using installutil.exe.

I am migrating to Blogger for all my new blogs. You may visit https://helpmedevelop.blogspot.in/ for more insights.

Leave a comment