How to cancel a web service call if it's not responding
I have a web page (.aspx) that calls a third party web service to get some data. It usually takes couple of seconds to get the response back, and then the rest of the page will load. Occasionally the call gets stuck either due to the web service is down, or internet connection, etc., the page just hang there and will not load.
My questions is:
1) Is there a way to abort/cancel the web service call after a set amount of time?
开发者_JAVA技巧2) Is it even possible to verify the status of the web service before calling it?
Thanks.
This question will point you in the right direction. It talks about how to set a default timeout for the web service, so it will automatically cancel if it takes too long.
timeout for asynchronous web service call in C#
The only way to verify the status of a service is by calling it. You can tell if it down by the response you get. (500 404 etc.).
Here is the difference between the two and what Microsoft recommends.
http://msdn.microsoft.com/en-us/library/ms998562.aspx#scalenetchapt10_topic14
There are multiple ways to handle this kind of problem. One of the biggest hangups of moving to a web app from non web-based applications is the responsiveness of the UI. If you want your interface to be more responsive to the user, you might want to think about using AJAX for async results. When the page loads, the section that is requiring a 3rd party web service can display some kind of loading indication (while everything else displays instantly), and then through RPC the content appears when it finished loading (or if a certain amount of time passed, displays a timeout error).
精彩评论