Consuming O16N Web Services from Azure Functions
Published Mar 23 2019 04:51 PM 966 Views
First published on MSDN on Sep 29, 2017
Operationalization feature of Microsoft Machine Learning Server allows us to publish R/Python models and code in the form of web services and the consume these services within client applications. This article outlines step-by-step details of consuming the published web service (R language) using Azure Functions (C# TimerTrigger). Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud without worrying about a whole application or the infrastructure to run it.

Step 1: Deploy Machine Learning Server

Create one-box/enterprise configuration using ARM Templates from here : Microsoft R Server 9.1 , Microsoft Machine Learning Server 9.2

Step 2: Publish Web Service

Let us publish a sample web service ManualTransmission to the above deployed configuration and generate a C# client to consume the web service using the following R code :

<Replace parameters in remoteLogin() with your own parameters>

Step 3: Use Visual Studio to Develop and Deploy Azure Function

Install Visual Studio 17 Update 3 (or later).

We will be using Visual Studio 2017 Tools for Azure Functions to create projects and deploy to Azure .

Open ManualTransmissionClient.sln from the Client Code Location from step 2 in VS17

Right Click ManualTransmissionClient Solution and Add --> Add New Project.

Choose Azure Functions from Visual C# Cloud, provide a name for the project “ManualTransmissionFunctionApp” and click OK

Now you will see a third project in our solution

In Solution Explorer, right-click on ManualTransmissionFunctionApp project and select Add --> New Item. Select Azure Function, type a Name for the class ManualTransmissionFunction.cs, and click Add.

Depending on your use case, you can choose the type of trigger. To make things simple, let us choose a timer trigger – a function which is triggered every 5 minutes.

Now we will add ManualTransmissionClient as a reference project so that we use client code in ManualTransmissionFunction.cs

Add Newtonsoft.Json and RestSharp Nuget Package for ManualTransmissionFunctionApp project using Manage Nuget Packages (since these nuget packages are used by the client project).

Once references and nuget packages are added , the dependencies will look similar to this :

Now add C# code to ManualTranmissionFunction.cs to call the web service :

To run this Azure Function locally, we need to define a storage account connection string for AzureWebJobStorage in local.settings.json file. Create a storage account (or) use an existing storage account connection string.

After updating the local.settings.json file, Set ManualTransmissionFunctionApp as Startup project, build the solution and run the app.

You will see that the function is called every 5 th minute and the prediction output is printed in the console. You can also debug this locally, by setting a breakpoint in the code.

Now lets publish this app from Visual Studio to Azure. Right Click ManualTransmissionFunctionApp and choose Publish.

Once you have published to Azure successfully, you can view the console output of Azure Function from Azure Portal as well.

The Visual Studio Solution is available in Github :

Other possible ideas using Azure Functions

Version history
Last update:
‎Mar 23 2019 04:51 PM
Updated by: