0

I see many people using ping to see if a server is up or not. In my test ping is ok but RPC is not allowed so it fails showing "The RPC server is unavailable".

How can I also test RPC before executing my entire code? (executed if ping is ok - see below)

var ping = new Ping();
try{

    var reply = ping.Send(server, 1000);
    if(reply.Status == IPStatus.Success /*Maybe add here AND RPC is ok*/){
       //do thousands of stuff - I ONLY want to enter here IF RPC IS OK

       /* Should have something here to test 
          RPC if(RPC==ok){ execute my huge code }
       */
    }

}catch(Exception ex){
   //message the error
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3912327
  • 1
  • 1
  • 7
  • Ping is a terrible way to check if a server is available anyway. ICMP is blocked in many environments. Your best bet is just to try a single RPC operation early and check for failure. Try to find an operation that is quick and simple to call, and check for the "RPC Server is unavailable" error. – Valdar Moridin Aug 12 '14 at 22:51
  • That's exactly what I am trying to do but I could not find anything for that. Do you have an example you can share? – user3912327 Aug 12 '14 at 23:06
  • I've got no information about what you're trying to do with RPC. "RPC Server is unavailable" usually occurs when the process needed to handle your request is not running. For example, calling EnumPrinterDrivers creates an RPC request to the spooler service. So what are you trying to do? – Valdar Moridin Aug 12 '14 at 23:39
  • If I were trying to check some processes that could happen but I am trying to get some OS info using ObjectQuery queryB = new ObjectQuery("select * from win32_OperatingSystem"); and that is running. – user3912327 Aug 13 '14 at 15:06
  • And I wanted to avoid the code being executed if an exception was thrown but it seems that even with the exception the code inside the try block gets initiated – user3912327 Aug 13 '14 at 16:59

0 Answers0