[英]How Do I Specify The WEB Test Results Output Folder Name In VS2012 Ultimate
[英]How do I connect to an ASMX web service in vs2012
我目前正在開發中。 我正在嘗試在Windows Store項目中連接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);
});
}
}
}
您的服務呼叫缺少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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.