-1
我是新的使用web服務,我試圖實現一種方法,但我遇到了麻煩。這是我想從一個響應的方法:從webservice調用異步方法
(awaitable) Task<getIbuttonDataResponse> SpecSrvClient.getIbuttonDataAsync(GetIbuttonDataInput getIbuttonDataInput)
Usage:
getIbuttonDataResponse x = await getIbuttonDataAsync(...);
這是WSDL生成的代碼爲「GetIbuttonDataInput」
public partial class GetIbuttonDataInput : object, INotifyPropertyChanged {
private string ibuttonIdField;
private string testerNameField;
[SoapElementAttribute(IsNullable=true)]
public string ibuttonId {
get {
return this.ibuttonIdField;
}
set {
this.ibuttonIdField = value;
this.RaisePropertyChanged("ibuttonId");
}
}
[SoapElementAttribute(IsNullable=true)]
public string testerName {
get {
return this.testerNameField;
}
set {
this.testerNameField = value;
this.RaisePropertyChanged("testerName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
編輯:
對不起,我不知道我無法發佈圖像,所以這讓我感到困惑。
我的問題是,當我試圖從web服務獲得響應時,如何傳遞ibuttonIDField字符串?這是獲得答覆所需的價值。
編輯2:
好了,所以這是我至今寫:
static class Program
{
//...
static void Main()
{
//...
getIbuttonDataResponse x = new getIbuttonDataResponse();
Response(serial, x);
//...
}
static async void Response(string[] serial, getIbuttonDataResponse x)
{
iButtonDB_Service.SpecSrvClient testrequest = new SpecSrvClient();
GetIbuttonDataInput input = new GetIbuttonDataInput { ibuttonId = serial[0], testerName = "me" };
x = await testrequest.getIbuttonDataAsync(input);
}
}
我只得到一個返回null,但可能是因爲數據庫值它試圖訪問尚未創建。
您沒有附加圖像。請添加它。張貼鏈接,我會爲你添加它。 – abatishchev
問題是什麼? –
你會得到一個空回報,因爲你沒有返回任何東西。您正將'getIbuttonDataResponse'傳遞給'Response'方法,而不是從那裏返回。嘗試'靜態異步任務響應(字符串[]串行){...返回等待testrequest.getIbuttonDataAsync(輸入);}' –