Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test to see if a net pipe service is listening

How can I test programmatically to see if a particular net pipe service is running and listening, so I don't get a "There was no endpoint listening at..." exception?

So for instance if I have this code:

Uri baseAddress = new Uri("http://localhost/something");
var _ServiceHost = new ServiceHost(typeof(Automation), new Uri[] { baseAddress });
NetNamedPipeBinding nnpb = new NetNamedPipeBinding();
_ServiceHost.AddServiceEndpoint(typeof(IAutomation), nnpb, "ImListening");
_ServiceHost.Open();

I want from another application communicate with http://localhost/something/ImListening but before I want to make sure is listening so I don't get an exception, or is the exception the only way to test this?

like image 930
Juan Avatar asked Oct 23 '22 15:10

Juan


2 Answers

Listen for the exception. That is the proper way to do it.

like image 98
Amadan Avatar answered Nov 15 '22 05:11

Amadan


Exceptions exists for a reason, I would just handle the exception, as long a you handle it the user wont get a cryptic error message, which I guess is what you are trying to avoid.

like image 25
ryudice Avatar answered Nov 15 '22 06:11

ryudice