400 неверных запросов, изменение конфигурации API управления службами Azure - PullRequest
3 голосов
/ 18 марта 2012

Моя проблема в том, что я получаю 400 неверных запросов, когда пытаюсь получить ответ на мой HTTP-запрос.Может кто-нибудь сказать мне, почему это происходит и, возможно, как я могу это исправить?

Точная ошибка: 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();
    }
}

}

1 Ответ

1 голос
/ 10 апреля 2012

BadRequest означает, что параметр был неверным.Я предполагаю, что вы используете слот развертывания 0 вместо постановки или производства, как указано здесь:

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

Кроме того, было бы здорово, если бы вы могли показать нампараметры, которые вы передаете, и мы можем из этого сказать, что не так.

...