Ruddy Lee 分享空間

Emergent Design 演化設計

讀取Windows Azure 上傳狀態的簡易console程式

leave a comment »

上一篇文章,沒有附上Source Code 被抗議了一下,好 ~~~ 這裡補上! 希望當你屢傳失敗時可以幫上一點忙…

這是我認為 最簡單讀取上傳狀態的程式 (Windows Azure Service Management API 中的 Get Deployment),比起上一篇乖乖的去讀 getOperationStatus 要簡單些,可以不用去讀取http header內的Request-id.

// 這是一支讀取 deployment 狀態的 Windows Azure Service Management API 程式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Security.Cryptography.X509Certificates;  // using X509 certificate
using System.Net;
using System.IO;

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

// 查詢 Deployment 的指令
var request = (HttpWebRequest)WebRequest.Create(“https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deploymentslots/staging“);
request.Headers.Add(“x-ms-version:2009-10-01“);       // Version 一定要加
request.ClientCertificates.Add(X509Certificate2.CreateFromCertFile(“C:/cer/XXXXX.cer“));  // 存放在Local 的 認證

try
{
var respStream = request.GetResponse().GetResponseStream();   //沒有Reponse 就會吃error
var xml = new StreamReader(respStream).ReadToEnd();
Console.WriteLine(XElement.Parse(xml));      // List 出來
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
Console.ReadLine();
}

}
}

附上原文的使用說明如下:

The Get Deployment request may be specified as follows. Note that you can return information about a deployment either by specifying the  deployment slot (staging or production), or by specifying the deployment’s unique name.

To generate the request URI, replace <subscription-id> with your subscription ID, <service-name> with the name of your service,
<deployment-slot> with staging or production, and <deployment-name> with the unique name of your deployment:

https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deploymentslots/<deployment-slot>/

有興趣的話,運用PowerShell 也能輕易地讀取這些訊息,也是一個好的選擇。如果你想做自己的工具的話,這裡有一篇文章可以做個開始的參考: http://blogs.msdn.com/b/mikekelly/archive/2010/03/05/a-powershell-cmdlet-for-managing-windows-azure-diagnostics.aspx

PowerShell for Windows Azure Service Management CmdLets: http://code.msdn.microsoft.com/azurecmdlets

Written by ruddyllee

2011 年 01 月 22 日 於 22:34:43

張貼於未分類

Tagged with

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

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

Twitter picture

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

Facebook照片

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

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: