2013-05-27 2 views
0

Je tente d'augmenter le nombre d'instances par code. Tout d'abord, j'ai créé un fichier .cer et un fichier .pfx et je le télécharge en .pfx vers les certificats de service de nuages ​​et .cer vers les paramètres -> certificats de gestion. Après j'ai utilisé le fichier .cer dans mon code. Je ne connais pas très bien ce fichier uplod c'est vrai?Azure Autoscaling (400) Bad Request

Voici mon code:

string subscriptionId = "c034e905-......"; 
     string serviceName = "multitenant"; 
     string configFileName = "ServiceConfiguration.cscfg"; 
     string roleName = "Multi.Web"; 

     XNamespace xs = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"; 
     XDocument configDocument = XDocument.Parse(String.Join("", File.ReadAllLines(Path.GetFullPath(configFileName)))); 
     XAttribute instanceCountAttribute = configDocument.Element(xs + "ServiceConfiguration") 
                  .Elements(xs + "Role") 
                  .Where(xRole => xRole.Attribute("name").Value == roleName).SingleOrDefault() 
                  .Element(xs + "Instances") 
                  .Attribute("count"); 

     int currentInstanceCount = int.Parse(instanceCountAttribute.Value); 

et je vérifie certains champs dans ma VM et j'incease mon currentInstanceCount.

double processorTotal = Convert.ToDouble(performanceCounter.CounterValue); 

      instanceCountAttribute.Value = (currentInstanceCount + 1).ToString(); 

      var serviceManagment = ServiceManagementHelper.CreateServiceManagementChannel("WindowsAzureEndPoint", 
       new X509Certificate2("multitenant.cer")); 
      var changeConfigInput = new ChangeConfigurationInput(); 
      changeConfigInput.Configuration = ServiceManagementHelper.EncodeToBase64String(configDocument.ToString()); 
      try 
      { 
       serviceManagment.ChangeConfigurationBySlot(subscriptionId, serviceName, "Production", changeConfigInput); 
      } 
      catch (WebException e) 
      { 
       throw new Exception(new StreamReader(e.Response.GetResponseStream()).ReadToEnd()); 
      } 

méthode ChangeConfigurationBySlot jette exception:

Le serveur distant a renvoyé une réponse inattendue: (400) Bad Request.

Où est-ce que je me trompe? Je ne pouvais pas comprendre. S'agit-il de paramètres de méthode ou de mauvais certificat de téléchargement?

Avez-vous des estimations?

Merci.

Répondre

0

J'ai résolu mon problème.

Il ne s'agit pas de certification. Premièrement, j'obtiens le fichier de configuration de production et je change le nombre actuel d'instances et le redéploie.

Voici le code:

déploiement var = managementClient.GetDeploymentBySlot (subscriptionId, serviceName, "Production");

 string configurationXml = ServiceManagementHelper.DecodeFromBase64String(deployment.Configuration); 
     serviceConfiguration = XDocument.Parse(configurationXml); 

     XNamespace xs = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"; 
     instanceCountAttribute = serviceConfiguration.Element(xs + "ServiceConfiguration") 
                  .Elements(xs + "Role") 
                  .Where(xRole => xRole.Attribute("name").Value == roleName).SingleOrDefault() 
                  .Element(xs + "Instances") 
                  .Attribute("count"); 
     currentInstanceCount = int.Parse(instanceCountAttribute.Value);