[英]Web Service asmx Xamarin.Form doesn't work
我的應用程序Android在執行代碼時顯示以下錯誤:“對象引用未設置對象的實例”。 好像“ e.Result”中什么都沒有。 但是,我的網絡服務運行良好
public MainPage()
{
InitializeComponent();
Please.GardaSoapClient Ws = new Please.GardaSoapClient(new BasicHttpBinding(),
new EndpointAddress("http://webgarda20170508110006.azurewebsites.net/Garda.asmx"));
Ws.HelloCompleted += Ws_HelloCompleted;
Ws.HelloAsync();
}
private void Ws_HelloCompleted(object sender, Please.HelloCompletedEventArgs e)
{
Device.BeginInvokeOnMainThread(async () => {
string error = null;
if (e.Error != null)
error = e.Error.Message;
else if (e.Cancelled)
error = "Cancelled";
if (!string.IsNullOrEmpty(error))
{
await DisplayAlert("Error", error, "OK", "Cancel"); **//error => "Object reference not set an instance of an object"**
}
else
`enter code here` {
test.Text = e.Result;
}
});
}
}
你能幫助我嗎 ? :) 謝謝
由於目標方法是事件處理程序,因此可以利用異步事件處理程序將事件arg e
保留在范圍內。
private async void Ws_HelloCompleted(object sender, Please.HelloCompletedEventArgs e) {
string error = null;
if (e.Error != null)
error = e.Error.Message;
else if (e.Cancelled)
error = "Cancelled";
if (!string.IsNullOrEmpty(error)) {
await DisplayAlert("Error", error, "OK", "Cancel");
} else {
test.Text = e.Result;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.