Didaxis
Didaxis

Reputation: 8756

How to Recycle a Self-Hosted WCF Service

I'm hosting a WCF Service in an Azure Woker Role much like this.

I'd like to be able to "recycle" the WCF Service Host on a regular interval. The problem is, I assume the service is running it's own App Domain, and I have no way to poll it for any events, nor can I share any common data between the Worker Role and the WCF Service.

For reference, here's the minimum code to host:

public override void Run()
{
    using(var host = new ServiceHost(typeof(MyService))
    {
        // Configure host here...

        host.Open

        while(true)
        {
            Sleep(1000);
        }
    }
}

I'd like to "restart" the host somehow every 24 hours, but i'm not sure how/what to hook into to accomplish that.

Upvotes: 3

Views: 939

Answers (1)

kwill
kwill

Reputation: 11008

The WCF service is running in-proc to your worker role right (ie. everything is running in WaWorkerHost.exe)? In that case you can either call RoleEnvironment.RequestRecycle, or just let the Run() method exit. Either way will cause WaWorkerHost.exe to gracefully shut down, and then the Azure guest agent will automatically restart everything.

Upvotes: 5

Related Questions