2012-03-18 10 views
3

私の問題は、私がHTTP要求に応答しようとすると、400の悪い要求を受け取ってしまうことです。 誰もがなぜこれが起こっているのか、おそらく私はそれを修正する方法を教えてもらえますか?400悪いリクエスト、Azureサービス管理APIの設定変更

正確なエラーがある: BadRequest設定の変化は、私は、設定ファイルを渡す前に、私はそれを見たとき、それは私がそれを変更したいものを変更していた私のコードにブレークポイントを入れ

を指定しませんしたがって、すでに存在する設定ファイルは、私が変更しようとしているものとは明確に区別されています。ここで

は、設定変更用のAPI情報です:http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx

そして、以下は私のコードで、すべてのヘルプは大歓迎され、あなたに

public void changeConfiguration(string serviceName, string deploymentSlot, string config, string deploymentName) 
{ 
//encoding the config file 
    byte[] encodedConfigbyte = new byte[config.Length]; 
    encodedConfigbyte = System.Text.Encoding.UTF8.GetBytes(config); 
    string temp = Convert.ToBase64String(encodedConfigbyte); 

//creating the URI with the subscriptionID,serviceName and deploymentSlot 
    Uri changeConfigRequestUri = new Uri("https://management.core.windows.net/" + subscriptionId + "/services/hostedservices/" + serviceName + "/deploymentslots/" + deploymentSlot + "/?comp=config"); 

//creating a request using the URI 
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(changeConfigRequestUri); 

//Adding a header to the request 
    request.Headers.Add("x-ms-version", "2010-10-28"); 
    request.Method = "POST"; 

//Create a string to hold the request body, temp being the config file 
    string bodyText = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
         "<ChangeConfiguration xmlns=\"http://schemas.microsoft.com/windowsazure\"" + ">" 
         + "<Configuration>" + temp + "</Configuration></ChangeConfiguration>"; 

//encoding the body 
    byte[] buf = Encoding.ASCII.GetBytes(bodyText); 
    request.ContentType = "application/xml"; 
    request.ContentLength = buf.Length; 

//searches the cert store for a cert that has a matching thumbprint to the thumbprint supplied 
    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 (certCollection.Count == 0) 
    { 
     throw new Exception("Error: No certificate found containing thumbprint "); 
    } 
    X509Certificate2 certificate = certCollection[0]; 

//cert is added to the request 
request.ClientCertificates.Add(certificate); 

//the requestBody is written to the request 
    Stream dataStream = request.GetRequestStream(); 
    dataStream.Write(buf, 0, buf.Length); 
    dataStream.Close(); 
    try 
    { 
    //retrieving responce 
     WebResponse response = (HttpWebResponse)request.GetResponse(); 
    } 
    catch (WebException e) 
    { 
     string test = new StreamReader(e.Response.GetResponseStream()).ReadToEnd(); 
    } 
} 

}

+0

ソリューションを[msdnのサンプルコード](http://msdn.microsoft.com/en-us/library/ee460795.aspx)と比較すると、 –

答えて

1

に感謝BadRequestは、パラメータを意味しました間違っている。その他

http://msdn.microsoft.com/en-us/library/ee460786.aspx

、あなたは私たちにあなたが渡しているパラメータを表示することができれば、それは素晴らしいことだ、ということ:私の推測では、ここで言及されるようにあなたが0の代わりに、ステージングまたは生産のdeploymentSlotを使用していることです私たちは多分何が間違っているかを知ることができます。

関連する問題