4

Does anybody know how to check whether Windows Server AppFabric caching service is up and running programmatically?

If the AppFabric service is down, it will throws an exception. That is a very expensive process, therefore I need to check if the service is up and running before create a cache object from the AppFabric.

This means that I want to use AppFabric as a caching service only if AppFabric is running, otherwise I want to use System.Web caching.

Example:

if (checking) 
   customCache = new WebDataCache(); 
else 
   customCache = new AppFabricDataCache();
Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
Telan Niranga
  • 437
  • 3
  • 10

1 Answers1

1

Its not that easy to do via C#. There's no management api exposed that'll allow you to check this programmatically directly. If you want to do this, you're going to have to make c# code to call the appropriate powershell cmdlet. There is an example in SO here:

You'll need to reference the system.management.automation assembly to do the business. The cmdlet you need to call is Get-CacheHost as it'll tell you whether the services are up or down. However, I've had some gotcha's with this. When you execute the cmdlet, it needs to be done under elevated rights. Also, the account your are executing it under needs to have administrative rights on the machine in the cache cluster you are pointed at. So.. this is not ideal. I tried to do this and stopped because of this.

Community
  • 1
  • 1
Nick Ryan
  • 2,662
  • 1
  • 17
  • 24
  • I am trying to do something similar to what you mentioned here. Were you able to get around the permissions issue? Did you ever come back to this? Thanks for any help! See my question for more detail: http://stackoverflow.com/questions/19987451/monitoring-appfabric-cache – MattW Nov 14 '13 at 20:25
  • @MattW No I didn't come back to it. I wasn't able to get around the restrictions described above (and in your question). I would say that AppFabric has been very reliable overall so I haven't had to give it much attention. – Nick Ryan Nov 15 '13 at 10:24