Изменение конфигурации Azi Service Mgmt Api (ошибка 400 неверных запросов) - PullRequest
1 голос
/ 14 марта 2012

Я пытаюсь загрузить файл конфигурации с помощью API управления Azure.Я получаю 400 ошибочных запросов и не могу понять, почему, какие-либо предложения?

Вот документация API для операции изменения конфигурации.http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx

А вот и мой код.Любые ответы с благодарностью

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

        Uri changeConfigRequestUri = new Uri("https://management.core.windows.net/" + subscriptionId + "/services/hostedservices/" + serviceName + "/deploymentslots/" + deploymentName + "/?comp=config");

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(changeConfigRequestUri);
        request.Headers.Add("x-ms-version", "2010-10-28");
        request.Method = "POST";

        string bodyText = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                          "<ChangeConfiguration  xmlns=\"http://schemas.microsoft.com/windowsazure\"" + ">"
                          + "<Configuration>" + temp + "</Configuration>              </ChangeConfiguration>";

        byte[] buf = Encoding.ASCII.GetBytes(bodyText);
        request.ContentType = "application/xml";
        request.ContentLength = buf.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 (certCollection.Count == 0)
        {
            throw new Exception("Error: No certificate found containing thumbprint ");
        }
        X509Certificate2 certificate = certCollection[0];
        request.ClientCertificates.Add(certificate);
        Stream dataStream = request.GetRequestStream();

        dataStream.Write(buf, 0, buf.Length);

        dataStream.Close();

            //Error occurs in the line below
            WebResponse response = (HttpWebResponse)request.GetResponse();

    }

}

1 Ответ

1 голос
/ 14 марта 2012

Нет тела для ответа от сервера?

Похоже, когда вы создаете свой URL, вы используете «deployName» там, где вы хотите «deploySlot».Может ли это быть?

...