简体   繁体   中英

Quick check if WCF endpoint is available (and how to handle if not)

I have a very simple WCF service running.

An ASP.NET web application is consuming this service from code behind during pageload like this:

try
{
    using (var myWCFClient = new MyWCFClient())
    {
       int myInt = myWCFClient.GetValue();
    }
}
catch (Exception ex)
{
}

Where "MyWCFClient" is the proxy object which is autogenerated when adding a service reference to my project.

Everything works fine, but the problem is when the Service Endpoint is down for some reason, it takes more than 30 seconds for the EndpointNotFoundException is catched. Of course this is unacceptable because it delays pageload since everything is synchronous. And because i have no simple mechanism to push the data to the page async after pageload, an async call to the WCF service is not preferred.

I also tried to set the sentTimeout in web.config to 5 seconds, but this doen't solve the problem. When is set the OperationTimeout of the InnerChannel to 5 seconds like this...

((IContextChannel)myWCFClient.InnerChannel).OperationTimeout = TimeSpan.FromSeconds(5);

...i do get a TimeOutException, but this exception is not throwed within 5 seconds, it also takes more than 30 seconds...

Does anybody knows how to handle this situation, or is there a way to quick check if the service is running before doing the actual call???

We use a ping function on the host that simply returns True in the response payload, and if you response takes longer than 5 seconds, we throw our own exception and exit the process. All the logic is on the client side, minus the Ping() function. We don't wait for the timeout exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM