Windows 应用商店应用 Web 服务使用
本文关键字:应用 服务 Windows Web | 更新日期: 2023-09-27 18:36:06
我有一个Windows Phone 7应用程序,其中包含以下代码
ServiceReference1.SMSWarriorServiceSoapClient ws = new ServiceReference1.SMSWarriorServiceSoapClient();
ws.BalanceCompleted += new EventHandler<ServiceReference1.BalanceCompletedEventArgs>(ws_BalanceCompleted);
ws.BalanceAsync(textBox1.Text, textBox2.Password);
现在我也想为Windows 8商店应用程序制作它。我试试这个
var client = new ServiceReference1.SMSWarriorServiceSoapClient() ;
var result = client.BalanceAsync("user", "pass");
resultDetails.Text = result.ToString ;
但没有运气我也尝试了Await,但我不知道如何使用它
如果要从事件句柄调用 Web 服务方法,请使用此方法。
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
var client = new ServiceReference1.SMSWarriorServiceSoapClient();
var result = await client.BalanceAsync("user", "pass");
resultDetails.Text = result.ToString();
}
如果要从某个方法调用 Web 服务方法,请使用此方法。
private async Task ServiceCall()
{
var client = new ServiceReference1.SMSWarriorServiceSoapClient();
var result = await client.BalanceAsync("user", "pass");
resultDetails.Text = result.ToString();
}
确保使用await
关键字调用方法ServiceCall()
。
如果使用 await,则必须使用 async 关键字或使用 Task
var client = new ServiceReference1.SMSWarriorServiceSoapClient() ;
var result = await client.BalanceAsync("user", "pass");
resultDetails.Text = result.ToString ;
例如:
// Put the keyword, async on the declaration of the event handler.
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
var respose=await <some async operation >
}