簡體   English   中英

C#,如何從異步/等待任務返回字符串作為結果

[英]C#, how to return string as result from Async/Await Task

我得到了調用第 3 方 WCF 服務的異步私有方法,作為回報它得到字符串值。 我已將 await 添加到 WCF 調用但出現錯誤

錯誤

'string' does not contain a definition for GetAwaiter and no accessible extension method accepting first argument of type string

代碼

 private async Task<string> InitializeCall()
    {
        string response = string.Empty;

        response = await eziClient.GetTransactionsAsync(username, "", BatchNumber.ToString(), "").GetAwaiter().GetResult();
        

        return response;
    }

不知道我在這里錯過了什么?

刪除.GetAwaiter().GetResult()

 private async Task<string> InitializeCall()
    {
        string response = string.Empty;

        response = await eziClient.GetTransactionsAsync(username, "", BatchNumber.ToString(), "");
        

        return response;
    }

.GetAwaiter().GetResult()的結果是一個string ,你不能await一個string

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM