Thursday, 29 November 2018

Create .NET Core Azure Function with Visual Studio 2017

Introduction

With all the talk about Serverless and Azure Functions, it’s a good time to learn how to do this if you don’t already know. In this post, we’ll do a walkthrough of you to create a simple .NET Core 2.1 Azure Function with Visual Studio 2017.

Prerequisites

First of all, let’s set up our environment.

1) Install Visual Studio 2017 (you can download the Visual Studio Community Edition for free here).

2) Install the .NET desktop development workload for Visual Studio. I have these options enabled:

image

image

3) Install the Universal Windows Platform development workload:

image

4) Install the ASP.NET and web development workload:

image

image

5) Install the Azure development workload:

image

image

6) Install the .NET Core cross-platform development

image

image

7) Install the Azure Functions Core Tools:

You can find more info here.

8) Install PostMan. This is a free tool for making HTTP requests so it’s great for testing out APIs. You can download it here.

Create a new Function App V2 project with Visual Studio 2017:

1) Create a new project in Visual Studio (File > New > Project)

image

2) Select Cloud > Azure Functions then select a folder and click OK.

image

3) On the new window that pops up, make sure you click the drop down and select Azure Functions v2 (.NET Core) and Http Trigger.

image

Click OK when done.

4) Let’s add some code. Rename Function1.cs to HttpTrigger.cs and add the contents below.

This method simply takes an HttpRequest input, extracts the two strings FirstName and LastName and outputs a greeting message.

Debug your Azure Function in Visual Studio

1) At the time of writing, there’s an issue with Visual Studio debugging for .NET Core Azure Functions V2. The workaround for this is here. Go ahead and go through this article then come back to continue at step 2.

2) Hit F5 to start debugging your function and you should be presented with something like this

image

As we can see, our function is running and the HttpTrigger is listed in green.

3) Let’s open up PostMan, create a new Request. It prompts you to create a request name and category.

image

image

4) Change the request to POST

image

5) Go to Body, select raw and add the JSON content below

image

6) In the console window, copy the HttpTrigger URL into PostMan:

image

image

7) Click Send in PostMan

You should get the greeting message below in PostMan

image

And you should see a request come through in the Azure Function console window

image

So, there you have it. Your first Azure Function running .NET Core 2.1. Hit Shift+F5 to stop debugging. You can find the project code on GitHub here.

8 comments:

  1. Great Article. Thank you for sharing! Really an awesome post for every one.

    IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

    ReplyDelete
  2. Wow! this is Amazing! Do you know your hidden name meaning ? Click here to find your hidden name meaning

    ReplyDelete