2013-07-25 24 views
0

我正在使用此代碼獲取部署配置。Azure管理服務API以某種加密格式提供部署配置

X509Store certificateStore = new X509Store(StoreName.My, StoreLocation.LocalMachine); 
certificateStore.Open(OpenFlags.ReadOnly); 
X509Certificate2Collection certs = certificateStore.Certificates.Find(
    X509FindType.FindByThumbprint, certThumb, false); 
if (certs.Count == 0) 
{ 
    Console.WriteLine("Couldn't find the certificate with thumbprint:" + certThumb); 
    return; 
} 
certificateStore.Close(); 

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(
    new Uri("https://management.core.windows.net/" + subID + 
      "/services/hostedservices/" + hostedServiceName + 
      "/deploymentslots/" + deploymentType)); 
request.Method = "GET"; 
request.ClientCertificates.Add(certs[0]); 
request.ContentType = "application/xml"; 
request.Headers.Add("x-ms-version", "2009-10-01"); 
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 
{ 
    // Parse the web response. 
    Stream responseStream = response.GetResponseStream(); 
    StreamReader reader = new StreamReader(responseStream); 

    // Display the raw response. 
    Console.WriteLine("Deployment Details:"); 
    string deployment = reader.ReadToEnd(); 

    // Close the resources no longer needed. 
    responseStream.Close(); 
} 

但我得到加密格式的配置。

但是,如果運行azure powershell,它會以純文本形式提供配置。

$deployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot 
$deployedConfig = $deployment.Configuration 

由於我必須使用服務管理API,我該怎麼做呢?

回答

2

這是expected behavior。 REST API以Base64編碼格式返回數據。由於Windows Azure PowerShell使用相同的REST API,因此它們將數據從Base64格式轉換爲人性可讀格式。這也是你需要做的。

因此,在你的代碼,你會做這樣的事情:

string clearText = System.Text.Encoding.UTF8.GetString(
         Convert.FromBase64String(reader.ReadToEnd())); 
+0

感謝拉夫。高度讚賞您的快速回復。 – sanjeev