VB.NET WinForms and ASP.NET Core API

VB.NET WinForms Development

ChatGPT

How do I create a VB.NET Forms app connected to an ASP.NET Core API?

To create a VB.NET Forms app connected to an ASP.NET Core API, you can follow these general steps:

Create an ASP.NET Core API project:
You can create an ASP.NET Core Web API project using Visual Studio 2019 or newer. Choose the ASP.NET Core Web Application template and select the API project type.
Define your API endpoints:
Define your endpoints in the API project, and make sure they return the data your VB.NET Forms app will use. You can use various methods to create endpoints, such as MVC controllers or routing.
Build and run the API project:
Build and run your API project to ensure it's working correctly. You can use tools like Postman or curl to test the endpoints and verify that they return the expected data.
Create a VB.NET Forms app:
Create a new VB.NET Forms app project in Visual Studio. Add any necessary controls to the form, such as text boxes or buttons, that will interact with the API.
Add a reference to the API project:
Add a reference to the API project in your VB.NET Forms app project. You can do this by right-clicking on the project in the Solution Explorer and selecting "Add Reference."
Make API calls from your VB.NET Forms app:
Use the HttpClient class in your VB.NET Forms app to make requests to the API. You can use methods such as GetAsync or PostAsync to retrieve or send data to the API.
Process the API responses in your VB.NET Forms app:
Handle the responses from the API in your VB.NET Forms app. You can deserialize JSON responses into objects using libraries such as Newtonsoft.Json. You can then use these objects to populate the controls on your form.
These are just general steps, and the specific implementation may vary depending on your requirements.

Form1.vb

I created a new project/solution

I selected the ASP.NET Core Web API template (with swagger)

I named the Web Application

I selected the .NET Core Framework version

I tested the API

Using Swagger User Interface

I added a second project

I selected the VB.NET Windows Forms App template

I gave the WinForms app a name

I selected a .NET Core version

I added a reference from the VB.NET WinForms app to the ASP.NET app (providing the VB.NET application with a understanding of the WeatherForecast type)

I selected the API project

I started the API project (dotnet run)

I added a button and two labels to the VB.NET WinForm screen and VB.NET code to call the API.