C#,如何从异步/等待任务返回字符串作为结果
c#
我得到了调用 3rd 方 WCF 服务的异步私有方法,作为回报,它获取字符串值。我在 WCF 调用中添加了 await 但出现错误
错误
'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()是 a string,而你不能awaita string。