I have backend project on ASP .NET Core. I write a web api into this project. Also, I have UI project on .NET Framework. I want to call web apis from .NET Frameowork and use it. What's best approches is it?
Seems you are trying to call Web API
from your Windows Form application
.
You can try this way:
On your Windows from Button Click event you can write this code snippet
private void Button2_Click(object sender, EventArgs e)
{
HttpClient _httpClient = new HttpClient();
string uri = "http://localhost:11951/api/MsAgent/GetMSAgentByAlias?alias=TestParam";
var _http_response = _httpClient.GetAsync(uri);
_http_response.Wait();
var _read_response = _http_response.Result.Content.ReadAsStringAsync();
_read_response.Wait();
if (_read_response.Result.Contains("No Data Found!"))
{
// Your Logic what you would like to do when no response
}
var data = JsonConvert.DeserializeObject<MSAgentViewModel>(_read_response.Result);
//Do what you wants to do with your API response
//Can Bind Data With From Property
}
This is one way, you can make the API Service Class
in diffrent class its up to you. Lot of best practice out there. Let me know if you require more help on this.