Generate Dynamic Barcode Image in Azure Function using Visual Studio, Entity Framework and Aspose.Barcode

Preface

In my previous post, I showed how did I installed and ran a simple Azure Function in my local environment using Visual Studio 2017 (15.3). In this post, I will show how can we create a function which can access the Database Server, fetch the model by Id and Generate a Barcode Image of the model’s barcode using a Third Party Library (Aspose.Barcode). Let’s start.

NOTE: Whole project can be found in github https://github.com/foyzulkarim/Azure. Please mark star the repo and if you have any question, please let me know.

Development

First we will create a new Azure Function App and update the packages. Detailed steps are shown in the previous post. I highly recommend you to check that before proceeding this part. 🙂

Then we will add two new function. Like below, we will choose HttpTriggerWithParameter for both of them. Let’s name these DownloadBarcodeByProductId and DownloadBarcodeByText.

After adding the functions, we will install Entity Framework and Aspose.Barcode package from nuget. I installed through Package Manager Console

Then we will add our required barcode generation code and logics.

Another thing to note is, we need to embed the connection string into the code. I couldn’t find any reference of using App.config / Web.config in this type of project yet.

Now lets go back to the actual function codes.  We will accept only GET request and we define our preferred route for accessing the function. And we accept the parameter as string values. In one function we accept the id and fetch the product’s data from database. In the other function, we accept the barcode and text values.

Both function will then call to the BarcodeImageHandler’s method.

The full project can be found in the Github https://github.com/foyzulkarim/Azure

If you find this interesting, or have any question, feel free to knock me in my Facebook Page Code Coopers  or email me at foyzulkarim@gmail.com

Testing

Now lets test the app.

If we run the application first time, it requires the permission of accessing network, like below.

Then, we can see there are two endpoints created. You can see the endpoints at the bottom of the console screen.

And if we request the endpoints using fiddler, the output should come accordingly.

 

In the next part, I will try to focus on publishing the function to Azure and how can we apply security mechanism on it.

 

#happyclouding

 

You May Also Like

About the Author: Foyzul Karim

1 Comment

  1. I’m impressed, I have to admit. Genuinely rarely should i encounter a weblog that’s both educative and entertaining, and let me tell you, you may have hit the nail about the head. Your idea is outstanding; the problem is an element that insufficient persons are speaking intelligently about. I am delighted we came across this during my look for something with this.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: