![](/img/trans.png)
[英]Azure Service Mgmt Api configuration change (400 Bad request error)
[英]Windows Azure service mgmt API Swap issue
我對使用azure service mangemement API相對較新。 我正在嘗試使用交換部署操作,但我一直收到一個我無法解決的錯誤。 因為我是azure的新手,所以我可能會完全錯誤地使用這個操作。 任何幫助深表感謝。
我得到的錯誤如下
<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();
}
}
這可能是因為您的服務名稱中包含大寫字母。 它應該都是小寫的。 但是,這就是說...有沒有理由你不只是使用示例客戶端而不是滾動自己的HTTP客戶端?
更新此答案:您必須擁有有效的XML,但其中的參數是部署名稱。 這是很少使用的東西之一。 它通常是GUID。 真正獲取此信息的唯一方法是使用GetDeployment調用或GetHostedService調用以及有關部署的詳細信息。 在該回復中,您將看到該名稱。 這個名字肯定與你提供的任何東西不同(我認為你使用的是標簽)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.