我尝试通过后面的代码增加实例数。
首先,我创建了一个.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中的一些字段,并且我会增加我的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 :(得分:0)
我解决了我的问题。
这不是认证。首先我获得生产配置文件,然后更改它的当前实例数并重新部署。
以下是代码:
var deployment = 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);