Checking WCF Service is up or not
-
2012年3月16日 17:51
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
全部回复
-
2012年3月16日 19:20
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
-
2012年3月17日 6:13
-
2012年3月17日 11:22
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: OKor 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
- 已标记为答案 Yi-Lun LuoModerator 2012年3月23日 11:49
-
2012年3月18日 19:33
Implement WCF Discovery:
This is an overview:
http://msdn.microsoft.com/en-us/library/dd456791.aspx
This is a walkthrough:
http://weblogs.asp.net/gsusx/archive/2009/02/13/using-ws-discovery-in-wcf-4-0.aspx
- 已标记为答案 Yi-Lun LuoModerator 2012年3月23日 11:49
-
2012年3月19日 9:24
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.
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
- 已标记为答案 Yi-Lun LuoModerator 2012年3月23日 11:49
-
2012年3月19日 11:32
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
-
2012年3月19日 12:24
Hi Ronit,
You can use WCF discovery to check if these services are up and running.
Regards,
nairooz Nilafdeen
-
2012年3月24日 16:16
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
- 已编辑 ronit_rc 2012年3月24日 16:27

