find a location for property in a new city

Wednesday, 11 January 2012

Using the Azure API to see a deployment status using .NET

See the status of your Windows Azure deployments using the Windows Azure Service Management REST API. Since this is REST based you can use any framework or programming language that can make web requests. Python, Java etc here is .NET.

Here is a short bit of C# code that will allow you to call the part of the Windows Azure Service Management REST API that deals with getting the status of your hosted service in Azure.

You can see how the REST API is expected to be used here at Get Hosted Service Properties. This code accesses that API:

static void Main(string[] args)
{
    var subsctiptionId = "f62e5e87-5c76-4a94-9136-794fae3eff16";
    var hostedService = "colintest";
    //I have another post that details how GetCertificateByThumbprint method works:
    //http://www.britishdeveloper.co.uk/2012/01/adding-certificate-to-request-in-net.html
    var certificate = GetCertificateByThumbprint("23A43AE81F15CB000000000000000000000000000");

    var statusApiUrl = string.Format(
       "https://management.core.windows.net/{0}/services/hostedservices/{1}?embed-detail=true",
       subsctiptionId, hostedService);
    var hostedServiceStatus = new Uri(statusApiUrl);
    Console.WriteLine("Hosted service status");
    MakeApiRequest(hostedServiceStatus, certificate);
    
    Console.ReadKey();
}

private static void MakeApiRequest(Uri requestUri, X509Certificate2 certificate)
{
    var request = (HttpWebRequest)HttpWebRequest.Create(requestUri);
    request.Headers.Add("x-ms-version", "2011-10-01");
    request.Method = "GET";
    request.ContentType = "application/xml";
    request.ClientCertificates.Add(certificate);

    try
    {
        using (var response = (HttpWebResponse)request.GetResponse())
        {
            Console.WriteLine("Response status code: " + response.StatusCode);

            using (var responseStream = response.GetResponseStream())
            using (var reader = new StreamReader(responseStream))
            {
                Console.WriteLine("Response output:");
                Console.WriteLine(reader.ReadToEnd());
            }
            Console.WriteLine("");
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        throw e;
    }
}

Since you have used ?embed-detail=true in the querystring this add extra detail. From here you can get all sorts of useful information such as: Status e.g. Running or DeploymentSlot e.g. Production.

Note: The GetCertificateByThumbprint(string thumbprint) method I used is of course simplifying attaching a certificate to the request for the sake of conciseness. You can have a look at what this method is doing here at attaching a certificate to a WebRequest.

Follow britishdev on Twitter

20 comments:

  1. What’s up, it's miles very splendid and beneficial net website. Keep shaping the notable feature, exceptional to discover your realistic internet web page. Thanks for tremendous and Informative post. This article is without a doubt consists of lot more information about this issue relies. College paper writing service giving many ideas and methods for thesis writing papers

    ReplyDelete
  2. I really had a great time with your post! I am looking forward to read more blog post regarding this!
    Happyroom2.com Tosstheturtle.net Catmariogame.com

    ReplyDelete
  3. Motifz Designer Lawn. 1, 2 & 3 Piece Unstitched Premium Embroidered Lawn 2019, Premium Lawn, Lawn 2019, Best lawn collection, Motifz, Best Lawn in Pakistan, Shipping worldwide. Stitching option available.

    ReplyDelete
  4. Awesome blog. I enjoyed reading your articles.
    tutu app
    tutuapp download

    ReplyDelete
  5. Wholesale printed custom perfume boxes with the highest quality and affordable prices. Free worldwide Delivery and free Custom Perfume Boxes design.

    ReplyDelete
  6. Buy online wholesale printed custom perfume boxes and packaging at easy prices and shipping worldwide, with 24/7 customer support. Get a free custom quote now!!

    ReplyDelete
  7. Blackbird packaging provide you with any size, shape design, custom cbd boxes sooner than any other packaging competitor in the market

    ReplyDelete
  8. mylar label bags in stock now. Ready made Cali pack designs. Fast Shipping at Your Supplies. Custom designs available

    ReplyDelete
  9. Blackbird packaging provide you with any size, shape design, custom cbd bath bomb boxes sooner than any other packaging competitor in the market

    ReplyDelete
  10. Blackbird packaging provide you with any size, shape design, custom wholesale cookie boxes sooner than any other packaging competitor in the market

    ReplyDelete
  11. Great Article
    Cloud Computing Projects




    Networking Projects



    Final Year

    Projects for CSE





    JavaScript Training in Chennai



    JavaScript

    Training in Chennai




    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals,

    Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer.

    Angular Training

    ReplyDelete
  12. cali spliff, available at Your Supplies. Cali Pack Heat sealable. Fast Shipping.

    ReplyDelete
  13. Packaging town is a one stop solution for the short-run cbd tincture boxes needs and supplies. At affordable prices. Request a free quote now.

    ReplyDelete
  14. Blackbird packaging provide you with any size, shape design, custom vape boxes sooner than any other packaging competitor in the market

    ReplyDelete