MSDN Community

Integrating Azure Machine Learning with .NET Applications

Learn how to seamlessly embed Azure ML models into your .NET projects, enabling powerful AI capabilities with minimal effort.

Overview

Azure Machine Learning (AML) provides a robust suite for building, training, and deploying ML models. This guide covers the steps required to consume those models directly from .NET using the Azure.ML SDK and REST endpoints.

Prerequisites

  • .NET 6.0 or later
  • Azure subscription with an AML workspace
  • Visual Studio 2022 or VS Code
  • Azure CLI installed

Step‑by‑Step Guide

  1. Create or select a model in your AML workspace and deploy it as a real‑time endpoint.
  2. Generate the endpoint key from the Azure portal.
  3. Add the Azure.AI.MachineLearning SDK to your .NET project:
    dotnet add package Azure.AI.MachineLearning
  4. Consume the endpoint from code:
    using Azure;
    using Azure.AI.MachineLearning;
    using System.Text.Json;
    
    var client = new MachineLearningClient(new Uri("https://<your‑workspace>.cognitiveservices.azure.com/"), new AzureKeyCredential("<endpoint‑key>"));
    
    var request = new
    {
        input = new { data = new[] { 5.1, 3.5, 1.4, 0.2 } }
    };
    
    Response<BinaryData> response = await client.PredictAsync("<endpoint‑name>", RequestContent.Create(JsonSerializer.Serialize(request)));
    Console.WriteLine(response.Content.ToString());
  5. Handle the response and integrate the prediction into your application logic.

Full Sample Project

Clone the sample repository for a ready‑to‑run project:

git clone https://github.com/msdn-community/azure-ml-dotnet-sample.git

Community Discussion

Alice 2 hours ago

Great guide! I was able to get my model running in minutes.

Bob 1 hour ago

Any tips on handling large payloads?

← Back to .NET AI topics | Related Articles