Согласно вашему описанию, я думаю, что код, который вы называете webapi, может содержать ошибку.Вы можете следовать моему рабочему коду, как показано ниже:
1.Публикация веб-приложения MVC и добавление виртуальных приложений.
2. Опубликовать веб-API в виртуальном пути.
3. Используйте HttpClient
для вызова webapi в HomeController
public ActionResult Index()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://xxx.azurewebsites.net/joeyAPI/api/");
//HTTP GET
var responseTask = client.GetAsync("values");
responseTask.Wait();
var result = responseTask.Result;
if (result.IsSuccessStatusCode)
{
var readTask = result.Content.ReadAsStringAsync();
readTask.Wait();
var students = readTask.Result;
ViewBag.Message = students.ToString();
}
}
return View();
}
Выход:
