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

25 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. Wholesale printed custom perfume boxes with the highest quality and affordable prices. Free worldwide Delivery and free Custom Perfume Boxes design.

    ReplyDelete
  5. 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
  6. Blackbird packaging provide you with any size, shape design, custom cbd boxes sooner than any other packaging competitor in the market

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

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

    ReplyDelete
  9. buy chiffon collection 2021 online from afrozeh at best prices. get free shipping in pakistan

    ReplyDelete
  10. Do your grocery online at Al-Fatah, Pakistan's best and largest online grocery website. Shop from a wide range of grocery including oil and ghee, tea and coffee, dry fruits and seeds, dairy and fresh bakery items, packaged foods, snacks and beverages, baby care, household essentials, fruits and vegetables and many more.

    ReplyDelete
  11. Shop from a wide range of Local and Imported variety of makeup removers and makeup remover online from Al-Fatah. Shop from a diversified range of makeup removers and makeup remover wipes from all top brands. Buy the best for your skin. Avail Free Delivery on orders above 1000 PKR for selected cities in Pakistan.

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

    ReplyDelete
  13. Buy active wear online pakistan from dshred at easy prices delivered at your doorstep. Get free shipping.

    ReplyDelete
  14. buy sports inner wear for ladies online from dshred at easy prices delivered at your doorstep. Get free shipping

    ReplyDelete
  15. NDURE presents the ultimate fashion formula for men in the form of mens shorts. Get the best chino shorts from NDURE that are not only sports shorts but also great for everyday wear. Our wide range of shorts for men is crafted keeping in mind your comfort. So shop online to get your hands on the best shorts in Pakistan.

    ReplyDelete
  16. buy tank tops for girls online from Dshred at easy prices delivered at your doorstep. Get free shipping

    ReplyDelete
  17. Buy juicer blender from Al-Fatah at best prices delivered at your doorstep. Get free shipping

    ReplyDelete
  18. it's a very informative post. thanks for sharing it. it's very helpful for me. Also check out Kinemaster mod

    ReplyDelete
  19. Shop for a huge range of makeup online and skin care products for both men and women at Al-Fatah, Pakistan’s leading chain of departmental stores. Shop from a huge range of top brands Women’s cosmetics and skin care products for both men and women from Al-Fatah. Free Delivery on orders above 1000 PKR in selected cities.

    ReplyDelete
  20. buy Electronics Online in lahore from Al-Fatah at best prices delivered at your doorstep. Get free shipping.

    ReplyDelete
  21. Thank you so much for sharing this. Would love to see more of these in the future. Keep up the good work! GBWhatsapp is also the best app right now! Can you make a guide on it!

    ReplyDelete
  22. Enem has the best available lingerie in Pakistan. So grab these amazing girls bras online from Enem Mall right now With Enem Mall, you can easily get the best luxury womens lingerie with ease.

    ReplyDelete
  23. Elevate the joy of Eid with our Pakistani festival dresses for kids. Embrace the spirit in style with enchanting outfits that blend tradition and modern flair, ensuring your little ones radiate charm on this special occasion. Pakistani festival dresses for kids

    ReplyDelete
  24. Looking to enhance your riding experience with your Meteor 650? Look no further! Our collection of Super Meteor 650 accessories is designed to complement your bike and elevate your journey to the next level. From sleek saddlebags to stylish windshields, we have everything you need to customize your Meteor 650 to suit your individual style and needs. Our accessories are crafted with the same attention to detail and quality as your Meteor 650, ensuring a seamless integration and unmatched performance. Whether you're embarking on a long-distance adventure or simply cruising around town, our genuine Meteor 650 accessories are sure to impress. Explore our collection today and discover the perfect additions to make your ride truly your own.

    ReplyDelete