简体   繁体   中英

Programmatically restarting IIS Hosted WCF service - change Bindings issue

I got into this not very good situation.. When web application starts - I set up different routes for my services so tenants of my multi-user app connect to:

private static void RegisterRoutes()
{
   // Setup URL's for each customer
   using (var cmc = new CoreModelContext())
   {
      foreach (var account in cmc.Accounts.Where(aa => aa.IsActive).ToList())
      {
         RouteTable.Routes.Add(
              new ServiceRoute(account.AccountId + "/mobile", 
                               new MyServiceHostFactory(), typeof(MobileService)));
      }
   }
}

So, when my site/service starts - it grabs all accounts from the database and sets up the routes.

This is a single point of failure right there. Sometimes servers rebooted in wrong order and if SQL Server not started - this service starts in "weird" mode.

Today web service stopped responding. I checked logs - IIS recycled pool as scheduled (default settings) and started different worked process. Something didn't click and boom - server stopped responding. Routes wasn't registered...

So. My question is.. How to fix it best way? I can put routes to config file, but that will mean I have to maintain those id's in 2 places. Probably not that bad but I'd rather do it differently if possible.

Is it possible to to programmatically try and restart pool? What happens when exception thrown in Application_Start ? Right now I'm not trapping it.

Not sure if this is a "fix" but when we've got similar dependency issues, we make sure the other dependencies cannot successfully start in "weird" mode. In this case, I would bring the app down hard if the sql server isn't avaliable, at least in production. Far better to have nothing being processed than have things being processed wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM