How to find bad endpoints earlier?

When I try to connect to an unavailable machine, I get an EndpointNotFoundException but it takes too long (about 20 seconds). Setting closeTimeout, openTimeout, receiveTimeout or sendTimeout has no effect. Can I get that exception earlier?


We're using the EnterpriseLibrary ConnectionMonitor block which works reasonably well, with it you can define your own strategy to determine connection availability but we're just using the one that comes in the box.

That default code (which does run on a background thread...handled by the block) uses this internally:

        public bool IsAlive(string hostnameOrAddress)
        bool alive = false;
            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;

Have a 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 block is part of the SCSF Smart Client Software Factory)

My understanding though is that you will need to do some kind of background threading OR wait for the timeout yourself. WCF doesn't know the endpoint doesn't exist until the call times out.

You can always try to connect in a separate thread, and have a timer with your desired timeout on the main thread. If your worker thread does not complete within your timeout, then you can assume that it won't respond.

Need Your Help

Get the HEAD version of a given file for streaming processing/diffing

git version-control diff git-diff

I'm generating a LaTeX document. I want to run a specialised latexdiff to compare my current (uncommitted) version against the last commit of a file, paper.tex.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.