Search code examples
c#wcfwcf-proxy

How to check if a WCF service is available?


Can I use Proxy.Open() as an indication to whether the connection should work or not? I would like to check if a connection is available first, and then, if its not, i won't make any calls to the service during the run of the application.

Note: I only need to check connectivity, not necessarily and entire client-service round-trip.

I Ended up creating a Ping() methods in the service as suggested.

FYI, using simply Open() just didn't work - Open() doesn't raise any exceptions even if the service is offline!


Solution

  • Given the fact that there are so many variables which influence success of a WCF Service call, I tend to add a dummy void KnockKnock()) method to the services to have a real proof if the connection works.

    This method can also serve a double purpose: You can call it async to notify the server that he has to be prepared for incoming requests. (Just the initial start-up of the service may take some time.) By invoking the KnockKnock() method the server can start loading the service and give your clients a better initial response performance.