You can use azure functions to create serverless solutions in EmpowerID. Developing the azure function allows you to develop, deploy a block of code and execute without server infrastructure or web server. Workflow studio has default templates to support the development of Azure Functions.
In this tutorial, you will learn how to do the following:
Create an Azure Function project in Workflow Studio
Open the project in Visual Studio
Add your implementation logic
Publish and deploy the Azure Function
Please follow the given instructions to create Azure Functions from the Workflow Studio template.
Open the Workflow Studio.
Right-click on the package folder you want to create the Web Job. Click on New Extension or Library → Azure Services .Net 6.0
Open the properties window for the extension and select the ServiceType property.
Azure Function (Isolated): Choose this service type to create functions that run out-of-process in Azure Functions.
Azure Function (InProcess): Choose the InProcess service type to run functions as a class library in the same process as the host.
Save the AzureFunction.
Double click the AzureFunction in the Solution Explorer to load it into Visual Studio.
Open the Appsettings.Json and update the AzureWebJobsStorage & FUNCTIONS_WORKER_RUNTIME values.
Please make sure that FUNCTIONS_WORKER_RUNTIME is dotnet-isolated for Azure Function (Isolated)
Please make sure that FUNCTIONS_WORKER_RUNTIME is dotnet for Azure Function (InProcess)
You can notice the default code in the Run method in the function.cs file, the default codes are different for In-Process and Isolated functions. You can modify the method to add your logic.
Azure Function - In Process
[FunctionName("AzFuncInProcessV6Function")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; string responseMessage = string.IsNullOrEmpty(name) ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." : $"Hello, {name}. This HTTP triggered function executed successfully."; return new OkObjectResult(responseMessage); }
Azure Function - Isolated
[Function("AzFuncIsolatedV6Function")] public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req) { _logger.LogInformation("C# HTTP trigger function processed a request."); var response = req.CreateResponse(HttpStatusCode.OK); response.Headers.Add("Content-Type", "text/plain; charset=utf-8"); response.WriteString("Welcome to Azure Functions!"); return response; }
Click on build or follow the instructions https://dotnetworkflow.jira.com/wiki/spaces/EDGV21/pages/1606357003/Deployment+Overview#Deploy-to-a-local-folder to deploy the Web Jobs files into a package. You can find the zip of the microservice inside ..\EmpowerID\WFS\_microservices folder. Look for the zip with the name of the WebJob you created.
Please follow the instructions here to https://dotnetworkflow.jira.com/wiki/spaces/EDGV21/pages/2676752385/Publish+EmpowerID+Microservice+to+Azure .
On successful deployment to azure, you can see the deployed function in the azure function app. A screenshot below shows a deployed isolated function.
Click on the function name to navigate to the details view. Click on the ‘Gen Function Url’ to get the function endpoint.
You can make an HTTP call to the endpoint of the AzureFunction to test.