joydip_kanjilal
Contributor

How to work with Azure Logic Apps in .Net

how-to
Aug 20, 20186 mins
Cloud ComputingMicrosoft .NETMicrosoft Azure

Take advantage of Azure Logic Apps to easily create and deploy cloud-based integrations and workflows

hand holding paper cloud for Microsoft Azure logo
Credit: Thinkstock/Microsoft

Automation of business processes and workflows is of paramount importance in today’s enterprises. With the increase in demand for cloud computing, enterprises need a way to integrate workflows and applications so as to maximize business efficiency and opportunity. This is exactly where Azure Logic Apps comes into play. 

Essentially, Azure Logic Apps are building blocks for automating business processes in the Azure cloud environment. They can be used to simplify integrations of apps and data in the cloud platform and build workflows seamlessly.

Note that both Azure Logic Apps and Azure Functions can be used to build applications on a serverless architecture in Azure. However, whereas Azure Functions refers to code that is triggered by an event, Azure Logic Apps relates to a workflow that is triggered by an event. 

I discussed working with Azure Functions in a previous post here. In this article I will provide a bird’s-eye view of Azure Logic Apps and how we can work with it in .Net.

Components of Azure Logic Apps

In this section we will learn the basic building blocks of Azure Logic Apps. Essentially, Logic Apps consist of four components. These include connectors, triggers, conditions, and actions.

  1. Connectors combine bundled code elements (actions and triggers) and an API to be used to connect to a particular service. As an example, if you were developing a Dropbox connector, you would provide the necessary credentials to connect to Dropbox.
  2. Triggers are typically used to initiate a workflow. Triggers are of three types, namely Push triggers, Pull triggers, and Recurrence triggers. So, you can have a trigger that is fired as soon as a file is created, moved, renamed, or deleted.
  3. Conditions are optional. Conditions are typically used to inject business logic into a workflow. As an example, your Logic App might need input and output, i.e., a file copy operation.
  4. Actions are steps that are performed when triggers execute—control flow steps in conditions, scopes, etc. Typically, an action denotes what you as the developer should do when an event occurs—say, when a message arrives. Depending on the message, you may want to invoke an API.

Creating an Azure Logic App project in Visual Studio

Now that we have the basics, let’s see how we can automate a workflow using Azure Logic Apps. Naturally, you’ll need to create an Azure account if you don’t have one. It’s free to start. Then start Visual Studio and follow the steps outlined below: 

  1. Click File -> New Project
  2. Select Cloud and then Azure Resource Group
  3. Specify a name and location for the resource group
  4. Click OK
  5. In the next screen, choose Logic App as the template (as shown in Figure 1 below)
  6. Click OK

After the project is created, you should see three files in the Solution Explorer window. These include a PowerShell deployment script and two JSON files. One of these two JSON files is the LogicApp.json file. This is where you will need to write the main logic of your Logic App. The other JSON file is named LogicApp.parameters.json. This is where you will specify the parameters. You may leave this file blank if no parameters are needed.

azure logic apps figure 1 IDG

Figure 1. Selecting the Logic App template to be used in your Visual Studio project. 

Using the Azure Logic Apps Tools for Visual Studio

You can click on the LogicApp.json file and write your logic there. However, rather than coding your app there, you may want to download and install the Azure Logic Apps Tools for Visual Studio from Tools -> “Extensions and Updates” in your Visual Studio IDE. Once you opt to download it, and you close all instances of Visual Studio running in your system, a VSIX installer will appear. Just follow the steps to install the tool.

When the installation is complete, you can open the LogicApp.json file using the designer. And that’s all there is to it. You can now create your Logic App workflow using the Logic App Designer in Visual Studio (see Figure 2 below). I will leave it to you to assemble your own custom logic here.

azure logic apps figure 2 IDG

Figure 2. The Logic App Designer in Visual Studio. 

Figure 3 below illustrates how you can create your Logic App in the Logic App Designer, step by step, simply by adding actions and conditions. Here the trigger is when a HTTP request is received by the application.

azure logic apps figure 3 IDG

Figure 3. Creating a Logic App using the Logic App Designer in Visual Studio. 

Deploying the Logic App using Visual Studio

Lastly, you should deploy the Logic App to Azure. This should be straightforward if you have an Azure account and you are logged into it. To deploy your Logic App, just follow the steps outlined below.

  1. Select the project in the Solution Explorer window in Visual Studio
  2. Right-click and select Deploy -> New
  3. Specify the subscription and resource group
  4. You may optionally specify template parameters
  5. Click Deploy when done

Note that you may use an existing resource group or create a new one when specifying the resource group. Once the Logic App has been deployed, you will be presented with a page that shows a few introductory videos and some commonly used triggers. You can use the Logic Apps Designer in Azure to extend your Logic App or create a new one from scratch. 

Cleaning up the Azure resources

Finally, when you are done using your Logic App, you can simply delete the resource group that contains your Logic App, which will delete the Logic App and any related resources. This is the easiest and fastest way to clean up, as you do not need to delete each and every resource used by your Logic App one after the other.

Azure Logic Apps provide an elegant way to take advantage of serverless computing. Logic Apps don’t incur any upfront or infrastructure costs—you pay only for resources consumed when the code has been executed. In essence, Logic Apps are scalable while at the same time providing a cheap solution for an enterprise’s integration and workflow needs.

joydip_kanjilal
Contributor

Joydip Kanjilal is a Microsoft Most Valuable Professional (MVP) in ASP.NET, as well as a speaker and the author of several books and articles. He received the prestigious MVP award for 2007, 2008, 2009, 2010, 2011, and 2012.

He has more than 20 years of experience in IT, with more than 16 years in Microsoft .Net and related technologies. He has been selected as MSDN Featured Developer of the Fortnight (MSDN) and as Community Credit Winner several times.

He is the author of eight books and more than 500 articles. Many of his articles have been featured at Microsoft’s Official Site on ASP.Net.

He was a speaker at the Spark IT 2010 event and at the Dr. Dobb’s Conference 2014 in Bangalore. He has also worked as a judge for the Jolt Awards at Dr. Dobb's Journal. He is a regular speaker at the SSWUG Virtual Conference, which is held twice each year.

More from this author