Testing a Machine Learning web service using a console application

Create a console application using Visual Studio to quickly test your Azure Machine Learning web service.

We assume that you have an Azure Machine Learning experiment and that you published it as a predictive web service.

We will also assume that you have never used Visual Studio. In this page, we list all the steps to test an Azure ML service even if you have no coding background.

Download Visual Studio 2015 Community Edition.


Install it with default parameters. About 8 minutes. You will be requested to reboot.

On Windows 10, in the Ask me anything search box, type Visual Studio  and double-click on Visual Studio 2015 to start it. You will be asked to log with a Microsoft account.

If you do not have one, here is where you can create a Microsoft account using your preferred email address:


You can decline to create a Visual Studio Online account if you do not want to do it at this time.

For this test, we are going to create a Console application in Visual Studio to test the service. The reason we are selecting a Console application is because the sample code provided by the Azure Machine Learning portal was written to run as a Windows Console application.

In another post, we will modify this sample code to be able to also call the web service from a submit button on a web page. See:


Here is the sample code used by this web service (minus the API Key and RequestURI)


In Visual Studio, under the File menu, click on New and then on Project.

Expand Templates – Visual C# and select Windows. In the center pane, select Console Application. In bottom of pane, give it a name (or accept the default name of ConsoleApplication1) and click Ok.

This is what you should see in Solution Explorer in the right pane.


Double-click on Program.cs to open it and delete all the existing code in this page.

In the Azure Machine Learning portal, open your published web service and make a copy of the API Key in notepad or any other text editor.

Verify that your web service is working by clicking on the Test button.

Enter the values for your experiment in the dialog box and click the check mark. Look in the bottom (black) ribbon for a result. If you do not get a result, you need to re-run/fix your experiment. If successful, you will see something like:

‘Experiment created on ?4?/?1?/?2016 [Predictive Exp.]’ test returned [“1″,”0.943256258964539”]…
Click on Details
You can see the Json that will be returned to your application when you call your ML web service.


Make a copy of this Json output and save it as well in notepad.

For this experiment, the Json returned is:

{“Results”:{“output1”:{“type”:”table”,”value”:{“ColumnNames”:[“Scored Labels”,”Scored Probabilities”],”ColumnTypes”:[“Int32″,”Double”],”Values”:[[“1″,”0.943256258964539”]]}}}}



In web page displayed, navigate down to Sample Code, select C#, click on Select Sample code, right-click and click Copy. Go back to Visual Studio and paste the complete code in the Program.cs page.

In the middle of the page, look for  “const string apiKey” and paste between the two double quotes the API key assigned to your ML web service. (Make sure no extra spaces are added.)

Slighty above, look for code similar to:
Inputs = new Dictionary() {
new StringTable()
ColumnNames = new string[] {"Average", "Attempts", "Exams"},
Values = new string[,] { { "87", "32", "5" }, { "98", "9", "5" }, }

And enter your own values for your experiment in Values.

Before continuing, we need to add a package:

In Visual Studio, click on Tools menu, then on Nuget Package Manager, and then on Package Manager Console.

You will get in the bottom window a PM prompt such as PM>


Install-Package Microsoft.AspNet.WebApi.Client

And press Enter. Wait for the command to complete and display success.

In Visual Studio, under Build menu, click on Build ConsoleApplication1 (or the name you assigned to your application). It should compile with no error.

Type CRTL-F5 to run without debugging and a MS-DOS console will open and display the Json file returned by the ML web service.


The Azure Machine Learning web service was tested successfully.

In another post, we will show how to call that ML web service from a submit button on a web page.



Leave a Reply