0

我目前是新开发的。我正在尝试在我的 Windows 商店项目中连接 Web 服务。

在此代码中没有错误,但它没有响应任何事情。我是想使用另一个代码还是将一些消息框放在来自 Web 服务的调用结果中?

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace Windows8App
{

public sealed partial class Login : Page
{  
    public Login()
    {
        this.InitializeComponent();
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    }

    private async void loginAsync(string username, string password)
    {
          ServiceReference1.Service1SoapClient service = new ServiceReference1.Service1SoapClient();
          var response = service.loginwebAsync(username, password);
    }

    private void btnLogin_Click(object sender, RoutedEventArgs e)
    {
          string user = txtUsername.Text;
          string pass = txtPassword.Text;

          System.Threading.Tasks.Task.Run(() =>
          {
              loginAsync(user, pass);
          });
    }
}
}
4

1 回答 1

0

您的服务调用缺少await关键字。像这样重写你的代码。如果有效,请将其标记为答案,否则我将删除我的答案。

private async Task loginAsync(string username, string password)
{
      ServiceReference1.Service1SoapClient service = new ServiceReference1.Service1SoapClient();
      var response = await service.loginwebAsync(username, password);
}

private async void btnLogin_Click(object sender, RoutedEventArgs e)
{
      string user = txtUsername.Text;
      string pass = txtPassword.Text;

      await loginAsync(user, pass);
}
于 2013-07-31T06:04:11.430 回答