We use the EnterpriseLibrary ConnectionMonitor block, which works quite well, with it you can define your own strategy for determining the availability of the connection, but we just use the one that comes in the box.
This default code (which runs in the background thread ... handled by the block) uses this inside:
public bool IsAlive(string hostnameOrAddress) { bool alive = false; try { Uri address = new Uri(hostnameOrAddress); HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(address); request.Timeout = 5000; using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) { alive = DoesResponseStatusCodeIndicateOnlineStatus(response); } } catch (WebException wex) { alive = DoesWebExceptionStatusIndicateOnlineStatus(wex); } return alive; }
Look at the block itself, see if you can use it in your project or get some ideas on how to solve your specific problem. (from memory, the unit is part of the Smart Client Software SCSF Factory software)
My understanding, however, is that you will need to do some background threads or wait for a timeout on your own. WCF does not know that the endpoint does not exist before the call expires.
source share