I have solution with 2 projects: Asp.Net WebApi Core and WinForms. I am going to consume services from WinForm.
Changed Solution Properties to startup multiple projects: 1st WebApi then WinForm (main form is FORM1).
Now, I have simple code like below:
private void button1_Click(object sender, EventArgs e)
{
TestAutentication().Wait();
Console.ReadKey();
}
static async Task TestAutentication()
{
HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("http://localhost:53791");
try
{
HttpResponseMessage response = await client.GetAsync("api/ValuesController");
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsAsync<string>();
Console.WriteLine("{0}", result);
}
else
{
Console.WriteLine("{0}", response.ReasonPhrase);
}
}
catch (HttpRequestException ex)
{
Console.WriteLine("{0}", ex.Message);
}
}
}
During startup browser opens and then FORM1. Clicking on button1 debugger is hanging when executing the line:
HttpResponseMessage response = await client.GetAsync("api/ValuesController");
What could be the reason for hanging?
Thanks in advance.