2013-05-27 145 views
0

我嘗試通過後面的代碼增加實例數。Azure Autoscaling(400)Bad Request

首先,我創建了一個.cer文件和.pfx文件,並將其上傳到.pfx到cloudservice證書和.cer以設置 - >管理證書。

在我的代碼中使用.cer文件後。我不太清楚這個uplod文件是真的嗎?

這裏是我的代碼:

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

,我檢查我的VM一些領域,我incease我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()); 
      } 

ChangeConfigurationBySlot方法是拋出異常:

遠程服務器返回一個意外的響應:(400)錯誤的請求。

我在哪裏錯了?我無法理解。是關於方法參數還是錯誤的上傳證書?

你有什麼估計?

謝謝。

回答

0

我解決了我的問題。

這不是關於認證。首先我得到生產配置文件,並更改它的當前實例數並重新部署。

下面是代碼:

變種部署= managementClient.GetDeploymentBySlot(subscriptionId,服務名, 「生產」);

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