Switch branches/tags
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.



This project is an example of how to use Consul in .NET applications further explained in this blog post.


  • Website

    A plain ASP.NET Core MVC application with one page showing some information from the services using DNS service discovery and a simple HttpClient calls.

  • DataService

    An ASP.NET Core web service which registers itself in consul and returns some data. It also exposes swagger API docs which can be used to generate clients from for example.

How Does It Work?

The Website's Home Controller>Index action does a DNS lookup, asking Consul for instances of the DataService. To do DNS lookups, it uses the DnsClient.NET library.

If a service instance was found, it takes the first result and calls the service via a simple HttpClient call. If mulitple instances were found, the Consul DNS endpoint does load balancing for us...

If you run the website only, there should be no results displayed, but also no errors on the page.

If one instance of the service is running, the website should show results of the service.

If two ore more instances of the service are running, the website should display the list of endpoints and the result of the HttpClient call. Refreshing the page a few times should show the automatic load balancing by the Consul DNS endpoint (as the results change every other call...)

Run the Project

To open the solution in Visual Studio, you'll need Visual Studio 2017 as this is the new MSBuild based project system.

You can also install the latest dotnet sdk and just run it via command line or call the RunAll.cmd which should (if everything works) download and start consul, start the website and two instances of the DataService.

Have fun playing with this :>