Web服务呼叫之前和期间的Internet连接 [英] Internet connection before and during web service call

查看:50
本文介绍了Web服务呼叫之前和期间的Internet连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序中,有一个登录页面需要进行网络服务调用.在调用网络服务之前,我们需要检查设备是否已连接到互联网.如果没有互联网,则显示一个消息框并单击``确定''.消息框中的按钮,保留在 相同的登录页面.

如果设备已连接到Internet,则继续进行Web服务呼叫.如果设备断开Internet连接,同时使呼叫显示一个消息框.

1.如何在拨打网络服务电话之前检查互联网连接?

2.在网络服务呼叫期间如何处理互联网连接检查?

在我的登录页面中,我的代码为:

private void btnLogin_Click(对象发送者,RoutedEventArgs e)
{

User.Login();  //制作Web服务的方法
User.LoginCompleted + = currentUser_LoginCompleted;

}

void User_LoginCompleted(布尔结果)
        {        
            Dispatcher.BeginInvoke(()=>
            {                     
               如果(res == true)
                    NavigationService.Navigate(new Uri("/Pages/Page5.xaml",UriKind.RelativeOrAbsolute));
               其他
                    MessageBox.Show(mssg.GetMessage(" Invalid")));
            }
        );

        } 

,然后在Login()中创建HttpWebRequest.

请帮助.

解决方案

您可以获取 网络接口信息,但是实际确定网络路径是否可用于您的预期目的地的唯一方法是实际尝试.

指示将超时.

您的应用可以在后台线程中发起请求,因此您的主UI在此期间仍可响应其他活动.

希望这会有所帮助,
标记


Hi,

In the app there is a login page which needs to make a web service call.Before the web service is called we need to check if device is connected to internet.If no internet then display a message box and on click of OK button in message box, remain in the same login page.

If the device is connected to the internet then proceed with the web service call.If the device is disconnected from internet connection while making the call display a message box . 

1.How can I check for internet connection before making the web service call?

2.How can I handle the check for internet connection during the web service call?

In my login page I have the code as:

private void btnLogin_Click(object sender, RoutedEventArgs e)
{

User.Login();  //method which makes web service
User.LoginCompleted += currentUser_LoginCompleted;

}

void User_LoginCompleted(bool result)
        {        
            Dispatcher.BeginInvoke(() =>
            {                     
                if (res == true)
                    NavigationService.Navigate(new Uri("/Pages/Page5.xaml", UriKind.RelativeOrAbsolute));
                else
                    MessageBox.Show(mssg.GetMessage("Invalid "));
            }
        );

        }  

and in Login() I make the HttpWebRequest.

Please help.

解决方案

Hi,

You can get network interface information but the only way to actually determine if a network path is available to your intended destination is to actually attempt it.

The indication will be a time out. 

Your app could initiate the request in a background thread so your main UI remains responsive to other activity in the meantime.

Hope this helps,
Mark


这篇关于Web服务呼叫之前和期间的Internet连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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