Fetching Hosting Services Name using Windows Azure Management API

Windows Azure Management API enables you to manage Azure subscription through codes. In this post, I will show,

how you could list hosted services inside your subscription through code ?

Windows Azure Management API is REST based API and allows you to perform almost all management level tasks with Azure subscription.

Any client making call to Azure portal using Management API has to authenticate itself before making call. Authenticating being done between Azure portal and client calling REST based Azure Management API through the certificates.

Read here to create certificate for Azure subscription

Read here to upload certificate

Very first let us create a class representing HostedService. There is property representing name of hosted service.

 public    class HostedServices
            public string serviceName { get; set; }

Essentially you need to perform four steps,

1. You need to create a web request to your subscription id


2. While making request you need to make sure you are calling the correct version and adding the cross ponding certificate of your subscription.


Note: I have uploaded debugmode.cer to my azure portal at subscription level.

3. Get the stream and convert response stream in string


You will get the XML response in below format,


4. Once XML is there in form of string you need to extract ServiceName from XML element using LINQ to XML.


On running you should get all the hosted service. For me there is only one hosted service debugmode9 under my Azure subscription.


For your reference full source code is as below,

using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Xml.Linq;

namespace ConsoleApplication26
    class Program
        static void Main(string[] args)

           var request = (HttpWebRequest)WebRequest.Create("https://management.core.windows.net/697714da-b267-4761-bced-b75fcde0d7e1/services/hostedservices");


            var response = request.GetResponse().GetResponseStream();
            var xmlofResponse = new StreamReader(response).ReadToEnd();

            XDocument doc = XDocument.Parse(xmlofResponse);
            XNamespace ns = "http://schemas.microsoft.com/windowsazure";
            var servicesName = from r in doc.Descendants(ns + "HostedService")
                               select new HostedServices
                                   serviceName = r.Element(ns + "ServiceName").Value

            foreach (var a in servicesName)





I hope this post was useful. Thanks for reading.

2 responses to “Fetching Hosting Services Name using Windows Azure Management API”

  1. […] Fetching Hosting Services Name using Windows Azure Management API […]

  2. […] And stepping through the code I found that ServiceOperations resolved to nothing. After a couple of hours of poking and prodding and then searching the internet I came across the solution in this post: Fetching Hosting Services Name Using Windows Azure Management API […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s