Try for free Book a demo

How to provision Azure Functions in Visual Studio and publish to Azure Portal

Microsoft Azure

3 Mins Read | Last modified on October 17th, 2024

How to provision Azure Functions in visual studio and publish to Azure portal-01

In this blog post, let us look at how to provision an Azure Function in Visual Studio and publish to the Azure portal. In addition, this blog also covers how to integrate the published Azure Function to a project in Microsoft Flow. It is a continuation of the Whitepaper – How to extract email attachment with Microsoft Flow.

Prerequisites:

  1. Visual Studio 2017 V15 or above
  2. Azure Subscription

Let us start with Provisioning a Function in Visual Studio

  1. Provisioning Function App in Visual Studio
    • Open Visual Studio and go to File-> New-> Project
    • In the New Project window, Select Azure Functions under visual C#
      1.New Project
    • Fill the Name field with custom name “checkIfSignaturePicture” and Click OK
    • In the new window that pop-up, select Run-Time version as “v2” and the trigger as “HTTP trigger” and Click Ok
      2.SelectRuntime

      Now, a new project would have created with some default sample code in it.

  2. Replace the default code
    • Delete the existing default code and paste the below-mentioned code. This plays a vital role in determining the signature picture and the actual attachment.
    • using Microsoft.Azure.WebJobs;
      using Newtonsoft.Json;
      using System.Threading.Tasks;
      using System;
      using HtmlAgilityPack;
      using System.Net.Http;
      using Microsoft.Extensions.Logging;
      
      namespace checkIfSignaturePicture
      {
          public static class checkIfSignaturePicture
          {
              [FunctionName("checkIfSignaturePicture")]
              public static async Task<bool> Run(HttpRequestMessage req, ILogger log)
              {
                  
                  bool isSignature = false;
                  try
                  {
                      string jsonContent = await req.Content.ReadAsStringAsync();
                      dynamic data = JsonConvert.DeserializeObject(jsonContent);
                      HtmlDocument htmlDoc = new HtmlDocument();
                      htmlDoc.LoadHtml(data["EmailBody"].Value);
                      var htmlNodes = htmlDoc.DocumentNode.SelectNodes("//img");
                      foreach (var node in htmlNodes)
                      {
                          if (node.OuterHtml.Contains(data["PictureName"].Value))
                          {
                              isSignature = true;
                              break;
                          }
                      }
                  }
                  catch (Exception ex)
                  {
                      log.LogInformation(ex.Message);
                  }
                  return isSignature;
              }
          }
      }
      
    • You need to add the HtmlAgilityPack library to initialize HtmlDocument class which is used to retrieve the content of the img tag.
    • 3.HtmlAgilityPack

    • The Function returns Boolean value based on the image depicted.
  3. Publish to Azure Portal
    • Right Click on the project name which you can find on the right side of the screen and select publish
    • 4. publish

    • In the new window which appear, select “Create New” option and hit Publish
    • A new window would appear now with set of options, select the appropriate subscription, resource group and click Create
    • 5.PublishCred

    • Now, you should see the publish process that has been started
    • Lastly, push “Publish” button to publish the Function App to the Azure portal

Azure Portal

Now, head to the Azure portal and follow the steps described below;

  1. Login in with your Azure Subscription account
  2. Click on the Function App in the left navigation bar
  3. 7. Azure portal home page

  4. The new window that appears may contain the list of Function App name. Select the right App that you have published from the Visual Studio, checkIfSignaturePicture.
  5. 8. list of functions

  6. Click on the appropriate App and you will be navigated to a new window
  7. Select the function inside the Function App from the left navigation bar
  8. You can now see the function is in read-only mode as it is published from Visual Studio
  9. Now, copy the function URL or endpoint from “Get function URL”
  10. collage

Integrate the Azure Function with Microsoft Flow

Head to the Microsoft Flow project and paste the copied Function URL or endpoint in the HTTP request action under URI field. The HTTP action uses this endpoint to send the parameters to the function in the portal and in return sends a response.

9. Integration with Flow

Wrap-up

In this blog, we have seen how to provision an Azure function in Visual Studio and Publish to the Azure Portal. Also, it described on integrating the Azure Function in the portal with Microsoft flow.

This article was originally published on Jul 10, 2019. It was most recently updated on Oct 17, 2024.

Azure Functions - Request Demo CTA

Related Articles