locked
Checking WCF Service is up or not RRS feed

  • Question

  • Hi,

    I want to check from client whether the hosted WCF service is running or up. What is the best practice for checking this? I have came across lots of solutions , here and there but not a concrete one. Could you please help us with an example?

    Thanks in advance.

    Regards

    ronit_rc

    Friday, March 16, 2012 5:51 PM

Answers

All replies

  • Hi Ronit_rc

    The simplest way is to add a Ping method to your service. If you have a lot of services and want a more generic solution then look at this code plex project.

    WCF Ping

    http://www.codeproject.com/Articles/90244/WCF-Ping

    Regards,

    JAXN


    MCTS: .NET Framework 4, Service Communication Applications

    Friday, March 16, 2012 7:20 PM
  • Hi,

    I want to check from my client code whether the service is running or not at runtime.

    Could it be done?Is there any examples regarding this?

    Regards

    ronit_rc

    Saturday, March 17, 2012 6:13 AM
  • Hi ronit_rc

    You would call the Ping method runtime. There is to my knowledge no other way do this without making a method that you call yourself.

    Just make this method:

    [OperationContract]
    public void Ping(){}

    You could even make it return a string with a small report - where you report whether all resources that are required by your service is also available.

    Like:

    <timestamp> DB access: OK
    <timestamp> Backend Service access: OK

    or you could return a more structured report object.

    This takes only a few minuts to add - I have done this several times to provide easy smoke-testing of services. What are you missing in such a solution?

    Regards,

    JAXN


    MCTS: .NET Framework 4, Service Communication Applications

    • Marked as answer by Yi-Lun Luo Friday, March 23, 2012 11:49 AM
    Saturday, March 17, 2012 11:22 AM
  • I always wish to have this feature in WCF out-of-box, but Unfortunately, WCF does not provide a built-in mechanism to support this. I can see of using .net extensibility feature to use here.

    For concrete implementation refer below link which provide a simple heart beat mechanism based on the messages that include a "Ping” header, so the client application can determine at any point whether the service is up or down.

    http://weblogs.asp.net/cibrax/archive/2010/05/17/enabling-service-availability-in-wcf-services.aspx

    This link may also provide some other thought.

    http://geekswithblogs.net/LeonidGaneline/archive/2008/05/07/wcf-availability-of-the-wcf-services.aspx

    Somehow I feel AppFebric in .Net 4.0 may have some built-in API to check this as this is designed for Service High Availability.


    Lingaraj Mishra

    • Marked as answer by Yi-Lun Luo Friday, March 23, 2012 11:49 AM
    Monday, March 19, 2012 9:24 AM
  • I guess you can perform a HTTP request to the WCF service and see if the status code that comes back is 200. If so then the service is available else the HTTP status code should give you the reason for the service not available.



    Rajesh S V

    Monday, March 19, 2012 11:32 AM
  • Hi Ronit,

    You can use WCF discovery to check if these services are up and running.

    Regards,

    nairooz Nilafdeen

    Monday, March 19, 2012 12:24 PM
  •  

    Hi,

    Thanks for your help. But I beleive WCF discovery is suitable only in intranet environment. Is it a solution for Internet environment?

    Also, I have 7 services. If I use  Ping method mechanism, then I have to implemet it for each services. Can I do anything generic?

    Regards

    ronit_rc


    • Edited by ronit_rc Saturday, March 24, 2012 4:27 PM
    Saturday, March 24, 2012 4:16 PM