Detect if wcf service is activated

ⅰ亾dé卋堺 提交于 2020-01-14 10:46:47

问题


I'm making a WP8 application. I noticed that if the server is working everything works good, but if the server is down I get an exception.

How can I check in the code if the wcf service is activated before using his methods?


回答1:


Implement a no-op method in your web-service and call it with a low timeout. If it works, the service is up. If the call fails for whatever reason, the service is down.

Actually, why is the server even down regularly? Maybe it is easier to ensure that it is available at all times.




回答2:


if you want to check if the server is up, you may use the Ping() class, in which you can easily define a timeout based on the network configuration, to assume server is running or not.

If you would like to check if the service is running on the server, you can define a method like this server side:

public bool IsRunning() { return true; }

and use a try-catch block client-side handling FaultException. When calling this method, it will either return true or an exception will be thrown if service is down. You may also want to check if your client WCF proxy is not in Faulted state before calling its methods.




回答3:


There is no way to learn this. It is a realy exceptional case. If you ensure the server is not down, easily to ping this or try download a simple static file like a text/html file soon as size of smaller one. supafly's answer is not wrong but it is same case as were you are.



来源:https://stackoverflow.com/questions/25105276/detect-if-wcf-service-is-activated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!