In this tutorial, you will learn how to create an asp.net core application and running on Dapr local environment.
This tutorial requires you have following server/components installed on your machine:
- .NET Core SDK
- Dapr CLI and initialize Dapr
Step 1 – Create ASP.NET Core Project
Before following steps, please make sure you have installed the .NET Core SDK. You can check installed .net core sdks by run following command:
$ dotnet --list-sdks
The output should be like:
2.1.4 [/usr/local/share/dotnet/sdk] 2.1.302 [/usr/local/share/dotnet/sdk] 2.2.300 [/usr/local/share/dotnet/sdk] 3.0.100 [/usr/local/share/dotnet/sdk] 3.1.201 [/usr/local/share/dotnet/sdk] 5.0.102 [/usr/local/share/dotnet/sdk]
Then you can create a a
sp.net core web api service
OrderService using command:
$ dotnet new webapi -o OrderService
-o OrderService parameter creates a directory named
OrderService with the source files for the app.
Run following command to Trust the HTTPS development certificate (On MacOS), for other platform refer to Get started with ASP.NET Core for detail:
dotnet dev-certs https --trust
Run following command under the OrderService folder to start up the service:
$ dotnet run
Call the built in rest API ,
a json result will be shown if everything goes well.
Stop the service, and let’s to run this api service on Dapr in next step.
Step 2 – Run the ASP.NET Core API Service with Dapr
Run following command under the
OrderService folder to start up the asp.net core api service with Dapr
$ dapr run --app-id order-service --dapr-http-port 5000 dotnet run
The output text that looks like the following, along with logs:
Try to call the api again:
https://localhost:5001/WeatherForecast and check the result. A json result should be responded.
1. Dapr list shows empty data
The api service is good, but the data is empty or 0 after running command:
This could be a bug of Dapr, will update this article when there are updates.
it is issue of the parameters
--dapr-http-port 5000 in the previous command, as
5000 or 5001 (https)port is the default port of asp.net core api service, so 5000 port is using by the api service.
use another available port or ignore both
--dapr-http-port in the command, and it works as well.
$ dapr run --app-id order-service --dapr-http-port 6000 -- dotnet run
$ dapr run --app-id order-service -- dotnet run
In this tutorial, you have learned how to create an
asp.net core api service with
dotnet core cli, and run the api service with