Getting started with Microsoft Service Fabric

How to get a simple Service Fabric stateful reliable service up and running

Dienstag, 24. April 2018

Getting an initial Service Fabric cluster and demo service up and running using Visual Studio 2018 is pretty easy but there are a few pitfalls.

Installation

  • Start the Visual Studio Installer and make sure the workload for Azure development is activated.
  • The Service Fabric tools are part of this workload. Also install the Microsoft Azure Service Fabric SDK and runtime using the web platform installer.

Create and setup the Service Fabric Application project

  • Start Visual Studio 2017 with elevated rights. If you don't start with elevated right you will not be able to initialize the local cluster and deploy the Service Fabric service.
  • Create a new project and choose the "Service Fabric Application" template.
  • Choose the "Stateful Service" template and give it a name, e.g. DemoStatefulService. Visual Studio 2017 will then create a Service Fabric Application solution containing two projects.
  • Make sure for both the "Service Fabric Demo" and "DemoStateFulService" project the build configuration is set to x64. Deployment to the cluster will fail if one of these is set to "Any CPU".
  • As of 04/24/2018, on non en-us versions of Windows 10 the stateful service process will crash because of an issue with the CoreCLR. This is already fixed for newer versions of the CoreCLR than the one used by default in the "Service Fabric Application" template. Please follow the following steps to manually target a higher CoreCLR version:
    • Open a command prompt and run "dotnet --info", note the version of the installed "Microsoft .NET Core Shared Framework Host".
    • Unload the "DemoStatefulService" project in Visual Studio 2017
    • Edit its project file and add "<RuntimeFrameworkVersion>2.0.6</RuntimeFrameworkVersion>" to the PropertyGroup node.
    • Reload the project
  • Finally hit F5 in Visual Studio 2017 and your first Service Fabric service should be up and running after a few seconds.

Stopping the local cluster and getting rid of its data

The Service Fabric cluster will keep running after you stop debugging your service. You can stop and remove the data associated with your local cluster completely using the "Service Fabric Local Cluster Manager" which you can find in the info area at the far right of the taskbar. Choose "Stop Local Cluster" if you want to keep the data that is associated with your stateful services. Choose "Remove Local Cluster" to stop the cluster and get rid of all associated data. Visual Studio 2017 will recreate the cluster automatically the next time you start your service.

References