Skip to main content

Create Azure Functions

Azure Functions enable you to create serverless solutions that execute code without managing server infrastructure. Workflow Studio provides templates for creating Azure Functions in two execution models: Isolated and InProcess.

What You'll Learn

This tutorial shows you how to:

  • Create an Azure Function project in Workflow Studio
  • Configure the function for Isolated or InProcess execution
  • Implement function logic in Visual Studio
  • Build and package the function for deployment

For deployment steps, see Publish EmpowerID Microservice to Azure Using PowerShell.

Execution Models

Azure Functions support two execution models:

  • Azure Function (Isolated) - Functions run in a separate worker process from the Azure Functions host
  • Azure Function (InProcess) - Functions run as a class library in the same process as the Functions host

The execution model determines the FUNCTIONS_WORKER_RUNTIME configuration value and affects the function code structure.

Create an Azure Function

  1. Open Workflow Studio.
  2. Right-click the package folder where you want to create the Azure Function.
  3. Click New Extension or Library > Azure Services .Net 6.0.
  4. Open the properties window for the extension and select the ServiceType property:
    • Select Azure Function (Isolated) to create an isolated function
    • Select Azure Function (InProcess) to create an in-process function
  5. Save the Azure Function.
  6. Double-click the Azure Function in the Solution Explorer to open it in Visual Studio.

Configure the Function

  1. Open the Appsettings.json file in Visual Studio.
  2. Update the configuration values based on your execution model.

For Isolated Functions

Set FUNCTIONS_WORKER_RUNTIME to dotnet-isolated:

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}

For InProcess Functions

Set FUNCTIONS_WORKER_RUNTIME to dotnet:

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}

Configuration values:

  • AzureWebJobsStorage - Connection string for Azure Storage used by the Functions runtime
    • UseDevelopmentStorage=true uses the local storage emulator for development
    • Replace with your Azure Storage connection string for production
  • FUNCTIONS_WORKER_RUNTIME - Specifies the execution model and must match your ServiceType selection

Implement Function Logic

The generated function includes default code in the Run method in the function.cs file. The code structure differs between execution models.

InProcess Function Template

[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);
}

Isolated Function Template

[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;
}

Modify the Run method to implement your custom logic.

Build and Package

  1. In Visual Studio, click Build > Build Solution to build the project.
  2. The build process creates a deployment package in the ..\\EmpowerID\\WFS\\_microservices folder.
  3. The package is a zip file named after your Azure Function.

This zip file contains the compiled function code, dependencies, and configuration files needed for deployment.

Deploy to Azure

To deploy your Azure Function to Azure, see Publish EmpowerID Microservice to Azure Using PowerShell.

Test the Function

After deploying to Azure:

  1. Navigate to your Azure Function App in the Azure Portal.
  2. Click Functions in the left menu to see the deployed functions.
  3. Click your function name to open the function details.
  4. Click Get Function Url to retrieve the function endpoint URL.
  5. Test the function by making HTTP requests to the endpoint:

Testing the InProcess template:

curl "https://your-function-app.azurewebsites.net/api/AzFuncInProcessV6Function?name=Test"

Expected response: "Hello, Test. This HTTP triggered function executed successfully."

Testing the Isolated template:

curl "https://your-function-app.azurewebsites.net/api/AzFuncIsolatedV6Function"

Expected response: "Welcome to Azure Functions!"

Replace your-function-app with your actual Function App name and include any required authentication keys in the URL.

Next Steps

  • Modify the function logic to implement your business requirements
  • Configure authentication and authorization for production
  • Set up Application Insights for monitoring and logging
  • Review Azure Functions documentation for advanced scenarios