MyService calls a REST uri using HttpClient.GetAsync(). I'm calling the service method from the Main method of a console app within the same solution but the following result is returned:
MyService使用HttpClient.GetAsync()调用REST uri。我在同一解决方案中从控制台应用程序的Main方法调用服务方法,但返回以下结果:
Id = 3, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"
What do I need to do to complete this REST implementation?
要完成此REST实现,我需要做什么?
MyService:
为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");
}
}
}
Service call from Console Main():
来自Console Main()的服务呼叫:
var result = new MyService().GetData();
UPDATE
UPDATE
Ok I updated my method implementation to look like this:
好的,我更新了我的方法实现,如下所示:
public async Task<HttpResponseMessage> GetData()
{
var result = await Client.GetAsync("https://www.test.com/users");
return result;
}
However, this still returns the same value that I included in my original post. What am I missing here?
但是,这仍然返回我在原始帖子中包含的相同值。我在这里想念的是什么?
1 个解决方案
#1
-2
You didn't returned anything from method
你没有从方法返回任何东西
public async Task GetData()
{
return await Client.GetAsync("https://www.test.com/users");
}
return your result from method.
从方法返回结果。
#1
-2
You didn't returned anything from method
你没有从方法返回任何东西
public async Task GetData()
{
return await Client.GetAsync("https://www.test.com/users");
}
return your result from method.
从方法返回结果。