0

我尝试通过后面的代码增加我的实例数。

首先,我创建了一个 .cer 文件和 .pfx 文件,并将其上传到 .pfx 到云服务证书和 .cer 到设置 --> 管理证书。

在我的代码中使用 .cer 文件之后。我不太清楚这个上传文件是真的吗?

这是我的代码:

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

我正在检查我的虚拟机中的一些字段,并增加我的 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) 错误请求。

我哪里错了?我无法理解。是关于方法参数还是错误的上传证书?

你有估计吗?

谢谢。

4

1 回答 1

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);
于 2013-05-27T14:24:41.740 回答