Azure Service Management API – via C#

I previously published an article showing how the Service Management API and the csmanage tool could be used to aid in the deployment of your Windows Azure application as part of your daily build.

Once I had began playing with the API’s, I wanted to be able to use them within an application so that I would be able to create something like a simple dashboard for managing your services without calling to csmanage all of the time.

Dominic Green - serviceManagementI started to do this by building up the REST requests within the application and performing a HTTP GET from my application. However, I then found this very handy library from Microsoft that has done the leg work around all of the calls needed for the service API (almost like a Blue Peter, here’s one I made earlier).

You can see in the code below that to utilize the library, we first need to create a ServiceManagementHelper class. This class will then be used to call out to each of the available services. To create this helper class we need to pass in a reference to an endpoint in app.config (show further down) and a reference to the certificate uploaded to manage our service.

namespace serviceManagementConsoleApplication
{
    class Program
    {
        private const string subscriberID = "...";

        static void Main(string[] args)
        {
            var serviceManagment = ServiceManagementHelper.CreateServiceManagementChannel				   ("WindowsAzureEndPoint", new X509Certificate2("insertcert"));

 	    var x = serviceManagment.ListHostedServices(subscriberID);

            foreach (HostedService s in x)
            {
                Console.WriteLine(s.ServiceName);
            }

            Console.Read();
        }
    }
}

As you can see in the code once the helper is set up we can call any of the services such as ListHostedServices which will return an list containing each service we have hosted in our account.

As mentioned above we need to have an endpoint set up for the helper class to call out to, the configuration for this is shown below.


  
    
      
        
          
          

          
        
      
    
    
      
    
  

With the configuration set up and the sample service management API library, we can easily get any application to call out and manage our cloud services.

Download the sample library here.

This entry was posted on Wednesday, January 6th, 2010 at 08:58 and is filed under Windows Azure. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “Azure Service Management API – via C#”

  1. Tweets that mention Azure Service Management API – via C# | domgreen.com -- Topsy.com Says:

    [...] This post was mentioned on Twitter by Dominic Green, Pascal Walschots. Pascal Walschots said: Windows Azure Service Management API Tool http://bit.ly/85gRMD via Dom Green http://bit.ly/8g2tVD [...]

  2. Flik Says:

    I did everything as you said, but an exception
    “The HTTP request was forbidden with client authentication scheme ‘Anonymous’.”
    is thrown!
    What should I do!?

Leave a Reply