Introduction to Azure Functions
Azure Function is a serverless compute service that enables user to run event-triggered code without needing to host it on the server and managing infrastructure. It is already hosted in the cloud.
Azure Function is a PAAS (Platform as a Service).
Supported Languages - Azure Functions support various languages like C#, F#, JavaScript, node.js and more.
Trigger - Azure Functions can be triggered with the configured trigger like HTTPTrigger, TimerTrigger, QueueTrigger and more.
In this series, we will be creating an Azure Function using-
- Azure Portal
- Visual Studio
And we will be calling Azure function via-
- Postman
- D365 CRM Plugin/Workflow
- Webhook
Create Azure Function using Azure Portal – Part 1
Previous Post - Introduction to Azure Functions
Step 1 – Login in to the Azure Portal, URL - "https://portal.azure.com/"
Step 2 - Click on "Create Resource".
Step 3 – Click on "Function App".
Step 4 – Fill all the information and click on "Review+Create" button.
Step 7 – Click on the "Functions".
Step 8 – Click on the "Add" button and select "HTTP trigger".
Step 9 – Name Azure Function and click "Create Function" button.
Step 10 – Click on the "Refresh" button and go to function by clicking on its name.
Step 11 – Click on the "Code + Test".
Step 12 – Now to test Azure Function, click on the "Test/Run" button.
Step 13 – Click on the "Run" button.
Step 14 – Whooooo!! We did it. 😊
Step 15 – Click on the "Get function URL".
Step 16 – Copy "END POINT URL" for further use.
Create Azure Function using Visual Studio – Part 2
Previous Post - Create Azure Function using Azure Portal – Part 1
Step 1 – Go to Visual Studio, create a "New Project" and select "Azure Function" template.
Step 2 – Name Function App and click "Create" button.
Step 5 – Right click on the Project Name and click "Publish" button.
Step 6 – Select Publish Target
Choose the publish target where you want to publish your Azure Function. If you want to publish it in existing Function App then choose Select Existing.
Here we will publish Azure Function in new Function App.
Step 7 - Click on the "Create" button.
Step 8 – Go to Azure Portal and click on the "Function App".
Step 9 – We will see recently created Function App in the list. Simply Click on it.
Step 10 – Click on the "Functions". But here we will find no Azure Function inside the app as its not yet deployed from Visual Studio.
Step 11 – Return to the Visual Studio and "Publish" it. By doing so Azure Function will be pushed in the Function App recently created.
Step 12 – If in case below popup occurs, Click on the "Yes" button.
Step 13 – Now go back to Azure Portal and refresh browser. We will find Azure Function successfully deployed.
Step 14 – Click on Azure Function and then Click "Code+Test".
Step 15 – In Test window we can not see code as it is deployed from Visual Studio.
Call Azure Function using Postman – Part 3
Previous Post - Create Azure Function using Visual Studio – Part 2
Step 1- Open Postman. Paste "End Point URL" of Azure Function in the POST method as below.
Previous Post - Create Azure Function using Visual Studio – Part 2
Step 1- Open Postman. Paste "End Point URL" of Azure Function in the POST method as below.
Step 2 – Follow the below Steps.
Step 3 – To run function, pass below as a request parameter.
Call Azure Function using Console Application – Part 4
Previous Post - Calling Azure Function using Postman – Part 3
In this part, we will create a Console Application (.Net Framework) and call Azure Function from it.
Step 1 – Open Visual Studio and create Console Application (.Net Framework) project.
Previous Post - Calling Azure Function using Postman – Part 3
In this part, we will create a Console Application (.Net Framework) and call Azure Function from it.
Step 1 – Open Visual Studio and create Console Application (.Net Framework) project.
Step 2 – Add a class “StudentDetail”and its data members as below.
We will be using these data members to send request to the Azure Function.
Step 3 – We will "set" static values to data members of the Student Details class.
Add below code to your “Program” class.
Step 4 – Create "WebClient" to call Azure Function.
We will use “WebClient” method for sending request and receiving response and “Newtonsoft Json” library to convert student object to json string that will be further used as request parameter to Azure Function.
Step 5 – Debug code line by line and see the request and response.
Call Azure Function from Dynamics 365 via Plugin– Part 5.1
Previous Post - Call Azure Function using Console Application – Part 4
Note - This blog will not focus on plugin creation.
Pre-Requisite -
i) Create an entity named "Test" with 2 columns as below.ii) Create and register plugin on entity "create" event
Plugin triggered on record creation will send the request to the Azure Function and the response will be updated on the source record.
Step 1 – Create a Class Library (.Net Framework) Project from your Visual Studio.Add a class “StudentDetail” and data member “name”. This data member will contain the request from Target (Test Entity record).
Step 2 – Add a method “CallingAzureFunction” to “DemoClass”
Step 3 – Add below code to the “Execute” method of plugin named “DemoClass”.
Step Note: As we have used external assembly "Newtonsoft.json", to register plugin assembly in Sandbox Mode will require DLL Merge. Refer to Post - D365 Plugin : Merge External Assemblies using IL Merge
Step 5 – After Successful registration of step, go to “Test" entity and create record.
Previous Post - Call Azure Function using Console Application – Part 4
Add a class “StudentDetail” and data member “name”. This data member will contain the request from Target (Test Entity record).
Step 2 – Add a method “CallingAzureFunction” to “DemoClass”
No comments:
Post a Comment