Search code examples
c#wcfnamed-pipes

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?


Solution

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