Microsoft Orleans – Direct client functionality

As usual, playing with Microsoft Orleans, is difficult to find good documentation and working examples to test available functionality.
Microsoft Orleans has a interesting co-hosting functionality that could be very usefull with small WebApi projects: Direct client. The goal of this functionality is to have only one process shared between the Silo and the WebApi client. This means that I will have only one running process, and not two (1- silo, 2- WebApi client). So it is easier to deploy and to run. As a plus, in development mode, it’s very annoing to run the silo, and after a while that it’s started, to run the clients.

Then I built a test project using Microsoft Orleans, Asp.NET Core and the Orleans’ Direct Client functionality that “allows co-hosting a client and silo in a way that let the client communicate more efficiently with not just the silo it’s attached to, but the entire cluster.”.

To give a complete and running example, this project implements:

  • a WebApi controller,
  • DI (Dependency Injection) example, injecting a custom Transient service in the controller,
  • grain storage using Azure Blob and Azure Table,
  • ProtobufNet serialization and a custom serialization for DateTimeOffset
  • Orleans Direct client

The source code is available in this github repository.

Update: You could also be interested in the ufficial 3.0 minimal example: Asp.Net Core 3.0 Co-hosting example on Microsoft/Orleans github

Co-hosting cluster and http client can be achieved using the Hosted client. This means that a Orleans Silo and a Http API may be the same process, so no serialization would be done in that case. Direct client is enabled by default from Orleans 2.3. The documentation is coming, take a look at the github issue here. In the meantime take a look to this stackoverflow thread.


  • Visual Studio 2019
  • Install Asp Net Core 2.2 SDK (> 2.2.301)
  • Install Azure Storage Emulator
  • (optional) Install Azure Storage Explorer (> 1.6.2)

Run it yourself

  • Install dotnet core 2.2 (or higher).
  • Run the Azure Storage Emulator
  • Run the WebApi: in src/06-Frontends/WebApi > run dotnet run, or using Visual Studio
  • Navigate to http://localhost:5000/api/v1/products to hit the WebApi GET endpoint
  • Navigate to http://localhost:8080/ for the Orleans Dashboard
  • (optional) Run the test client: in src/06-Frontends/TestClient > run dotnet run, or using Visual Studio


This code should be considered experimental. It works, however the project may have rough edges and has not been thoroughly tested. I welcome feedback!


Add a Comment

Your email address will not be published. Required fields are marked *