MyService使用HttpClient.GetAsync()调用REST uri。我在同一解决方案中从控制台应用程序的Main方法调用服务方法,但返回以下结果:
Id = 3, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"
完成此REST实现需要做什么?
为MyService:
using System.Net.Http;
using System.Threading.Tasks;
namespace Services
{
public class MyService
{
private static HttpClient Client = new HttpClient();
public void GetData()
{
var result = await Client.GetAsync("https://www.test.com/users");
}
}
}
来自Console Main()的服务呼叫:
var result = new MyService().GetData();
UPDATE
好的,我更新了我的方法实现,如下所示:
public async Task<HttpResponseMessage> GetData()
{
var result = await Client.GetAsync("https://www.test.com/users");
return result;
}
但是,这仍然返回我在原始帖子中包含的相同值。我在这里错过了什么?
你没有从方法返回任何东西
public async Task GetData()
{
return await Client.GetAsync("https://www.test.com/users");
}
从方法返回结果。