I have a Web API project and I am trying to call some of the API(s) from an ASP.net Core application. The code is like below:
var connectionViewModel = new ConnectionViewModel()
{
ConnectionId = connectionId,
MemberId = Guid.Parse(memberId),
ReconnectOn = DateTime.Now
};
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:63892/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.PostAsJsonAsync("api/app/chat/connection/PostConnection", connectionViewModel).Result;
response.EnsureSuccessStatusCode();
and here is the web api
[HttpPost]
public async Task<IHttpActionResult> PostConnection(ConnectionViewModel viewModel)
{
var validation = await connectionService.CreateConnection(viewModel);
if (validation.IsValid)
{
return Ok(resultSet.CreateResultSet(validation));
}
else
{
return BadRequest(validation.Message);
}
}
the problem is view Model is always null. I use the same code to call the web api from console application or another web api application and it works fine. But it does not work when I use inside asp.net core application.
Thanks
connectionViewModelfrom the same assembly as what the API is using? If not, does it have the same exact properties?connectionViewModelvsviewModel?