This article is contributed. See the original author and article here.

This article helps you to Deploy an existing Asp.net Core Web API project as Guest executable to Service Fabric Cluster.


 


Step 1: Publish Asp.Net Core Application to Folder.


 


Right-click the .NET Core project and click Publish.


Create a custom publish target and name it appropriately to describe the final published service.


reshmav_0-1623376676852.png


reshmav_11-1623377234316.png


You have now published the service to a directory.


Go to the path where Project is published, you will see an exe created for your project.


reshmav_8-1623376989577.png


 


Step 2: Creating a Guest Service Fabric Application



  1. Choose File -> New Project and Create a Service Fabric Application. The template can be found under Visual C# -> Cloud. Choose an appropriate project name as this will reflect the name of the application that is deployed on the Cluster.

  2. Choose the Guest Executable template. Under the Code Package Folder, browse to previously published directory of service.

  3. Under Code Package Behavior you can specify either Add link to external folder or Copy folder contents to Project. You can use the linked folders which will enable you to update the guest executable in its source as a part of the application package build.

  4. Choose the Program that needs to run as service and specify the arguments and working directory if they are different. In below example we are using Code Package.

  5. Click on Create.


reshmav_9-1623377018896.png


If your Service needs an endpoint for communication, you can now add the protocol, port, and type to the ServiceManifest.xml


For example:


 <Endpoint Protocol=”http” Name=”AccountServiceEndpoint” Type=”Input” Port=”5000″ />


 


The Application Url and Port can be verified from launchSettings.json of your Asp.Net Core Web API project.


Sample for reference:


{


  “iisSettings”: {


    “windowsAuthentication”: false,


    “anonymousAuthentication”: true,


    “iisExpress”: {


      “applicationUrl”: “http://localhost:62871“,


      “sslPort”: 0


    }


  },


  “$schema”: “http://json.schemastore.org/launchsettings.json“,


  “profiles”: {


    “IIS Express”: {


      “commandName”: “IISExpress”,


      “launchBrowser”: true,


      “launchUrl”: “weatherforecast”,


      “environmentVariables”: {


        “ASPNETCORE_ENVIRONMENT”: “Development”


      }


    },


    “webapi2”: {


      “commandName”: “Project”,


      “launchBrowser”: true,


      “launchUrl”: “weatherforecast”,


      “environmentVariables”: {


        “ASPNETCORE_ENVIRONMENT”: “Development”


      },


      “applicationUrl”: “https://localhost:5001;http://localhost:5000


    }


  }


}


Service Manifest file:


<Endpoints>


      <Endpoint Name=”GuestExecProjectTypeEndpoint” Protocol=”http” Type=”Input” Port=”5000″ />


</Endpoints>


 


Now, you are set to deploy the Guest Executable Project to Service Fabric cluster.


 


Step 3: Deploy the Guest Application to Azure Service Fabric cluster


reshmav_4-1623376676878.png


From SFX: 


reshmav_5-1623376676884.png


 


Step 4: Accessing the Web API from Cluster Node


RDP inside the node and Hit the API endpoint.


Eg:  http://localhost:5000/weatherforecast


reshmav_10-1623377057883.png


 


In case you are not sure, in which port application is listening, please find an alternative way to check:


If deployed in Azure:



  • RDP inside the node and get the Process ID of exe.

  • Run netstat -ano


reshmav_7-1623376676907.png


 


Reference: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-deploy-existing-app


https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-guest-executables-introduction


 


 

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.