2011-12-14 68 views
3

我對使用azure服務管理API比較陌生。我正在嘗試使用交換部署操作,但我一直收到一個我無法修復的錯誤。因爲我是嶄新的天藍色,我可能會完全錯誤地進行這種操作。任何幫助深表感謝。Windows Azure服務管理API交換問題

我得到的錯誤是以下

<Error xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Code>ResourceNotFound</Code><Message>The resource service name hostedservices is not supported. If it is a new partner service please ensure that the service is registered in RDFE.</Message></Error>" 

這裏是我的代碼,我在這其中發生異常

public void swapDeployment() 
    { 

     String operationName = "hostedservices"; 
     String prodName = "HealthMonitor - 21/10/2011 22:36:08"; 
     String sourceName = "SwapTestProject - 13/12/2011 22:23:20"; 

     Uri swapURI = new Uri("https://management.core.windows.net/" 
          + subscriptionId 
          + "/services/" 
          + "hostedservices" 
          + "/stevenRiordanHello/"); 

     HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(swapURI); 

     request.Headers.Add("x-ms-version", "2009-10-01"); 
     request.Method = "POST"; 
     request.ContentType = "application/xml"; 

     String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Swap xmlns=\"http://schemas.microsoft.com/windowsazure\"><Production>"+prodName+"/Production><SourceDeployment>"+sourceName+"</SourceDeployment></Swap>"; 
     byte[] bytes = Encoding.UTF8.GetBytes(xml); 
     request.ContentLength = bytes.Length; 

     X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); 

     try 
     { 
      certStore.Open(OpenFlags.ReadOnly); 
     } 
     catch (Exception e) 
     { 
      if (e is CryptographicException) 
      { 
       Console.WriteLine("Error: The store is unreadable."); 
      } 
      else if (e is SecurityException) 
      { 
       Console.WriteLine("Error: You don't have the required permission."); 
      } 
      else if (e is ArgumentException) 
      { 
       Console.WriteLine("Error: Invalid values in the store."); 
      } 
      else 
      { 
       throw; 
      } 
     } 

     X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false); 
     certStore.Close(); 

     if (0 == certCollection.Count) 
     { 
      throw new Exception("Error: No certificate found containing thumbprint " + thumbprint); 
     } 

     X509Certificate2 certificate = certCollection[0]; 

     request.ClientCertificates.Add(certificate); 

     using (Stream requestStream = request.GetRequestStream()) 
     { 
      requestStream.Write(bytes, 0, bytes.Length); 
     } 
     try 
     { 
      //exception is caught at the end of the line below 
      using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 
      { 
       if (response.StatusCode != HttpStatusCode.OK) 
       { 
        string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode); 
        throw new ApplicationException(message); 
       } 
      } 
     } 
     catch(WebException e) 
     { 
      StreamReader sr = new StreamReader(e.Response.GetResponseStream()); 
      string errorText = sr.ReadToEnd(); 
     } 
    } 

回答

1

這可能是因爲您的服務名稱有大寫字母指定在裏面。它應該都是小寫的。然而,這就是說...是否有一個原因,你不會只使用示例客戶端而不是滾動自己的HTTP客戶端?

更新此答案:您必須擁有有效的XML,但其參數也是部署名稱。這是那些很少使用的東西之一。它通常是一個GUID。要真正獲得此信息的唯一方法是使用GetDeployment呼叫或GetHostedService呼叫以及有關部署的詳細信息。在那個迴應中,你會看到這個名字。這個名字絕對不同於你提供的任何東西(我認爲你使用的是標籤)。

+0

感謝您的回覆,我將服務名稱更改爲全部小寫,並且仍然收到相同的錯誤。我的代碼是基於代碼從這裏http://msdn.microsoft.com/en-us/library/windowsazure/ee460782.aspx列出您的託管服務。此代碼爲我工作。但是我知道的代碼是用於GET,其中swap部署操作是POST。 – StevenR 2011-12-14 17:24:59