简体   繁体   中英

Azure Service Mgmt Api configuration change (400 Bad request error)

i am trying to upload a configuration file using the azure management api. I am getting a 400 bad request error and i cannot figure out why, any suggestions?

Here is the API doc for the change configuration operation. http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx

And here is my code. Any responces greatly appreciated

 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();

    }

}

Is there no body to the response from the server?

It looks like when you're constructing your URL, you're using "deploymentName" where you want "deploymentSlot." Could that be it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM