I writing an app using WPF and i want to use HTML + JS to simply present some information. So, the idea is simple - send POST request to Web Api, make it store data (like a global variable), and via GET request get data from API. And there is the problem. When i post data to WebApi controller and save it in my global variable, and then trying to get it from there with GET request, i getting nothing but value that was before editing with POST request (i mean QuestionList stays equal empty list). How should i store info before sending it to web page? Or there is some more simple way to use html to present information in WPF application?
Below you can find my ApiController code and code of my class that i use in WPF application.
Thank for your attention.
namespace WebApp.Controllers
{
public class WebFormsController : ApiController
{
private List<RegisterQuestion> QuestionsList = new List<RegisterQuestion>();
// POST: api/WebForms
public string PostQuestions(List<RegisterQuestion> questions)
{
QuestionsList = questions;
return "OK";
}
public string GetQuestions()
{
string json = JsonConvert.SerializeObject(QuestionsList);
return json;
//QuestionsList = questions;
}
}
}
And other class
public class WebWorking
{
private static string APP_PATH = "http://localhost:60327";
static HttpClient client;
//TODO: rename
public WebWorking()
{
client = new HttpClient();
client.BaseAddress = new Uri(APP_PATH);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public async Task<string> PostQuestionListToAPIAsync(List<RegisterQuestion> questions)
{
HttpResponseMessage response = await client.PostAsJsonAsync("/api/WebForms/PostQuestions", questions);
return "Posted";
}
}
Aucun commentaire:
Enregistrer un commentaire