如何处理WebService异常? [英] How to handle the WebService Exceptions?

查看:110
本文介绍了如何处理WebService异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,



我的项目包含Web服务...当互联网断开连接时,我必须处理网络异常而不抛出任何错误。你能告诉我怎么办吗?请给我解决这个问题的方法。

Hi sir,

My Project is containing Web services...When internet is disconnected,I have to handle the web exceptions with out throwing any errors..Could you please tell me how to handle it? Kindly give me the solution for this problem.

推荐答案

包含 System.Net 参考并按照下面的代码



Include System.Net reference and follow the code below

public static bool CheckForInternetConnection()
{
    try
    {
        using (var client = new WebClient())
        using (var stream = client.OpenRead("http:\\www.google.com"))
        {
            return true;//Tried pinging the site that almost up all the time.
        }
    }
    catch
    {
        return false;
    }
}





调用上面的函数,你要检查连接可用性并抛出错误,如< br $>




Call the above function where you want to check connection availability and throw the error like

Response.Write("<script type='text/javascript'>");
Response.Write("alert('Check Internet Connection.');");
Response.Write("</script>");





这个你可以查看天气是否可以上网。另外,请参考以下链接



检查c#中是否提供互联网连接 [ ^ ]



如何在Silverlight应用程序中ping网络IP或主机名? [ ^ ](基于silverlight,但会帮助你)



By this you can check weather internet is available or not.Further,refer to below links

check internet connection available or not in c# [^]

How to Ping network IP or Hostname in Silverlight Application?[^](Its based on silverlight but will help you bit)


这篇关于如何处理WebService异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆