繁体   English   中英

Azure自动缩放(400)错误请求

[英]Azure Autoscaling (400) Bad Request

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

首先,我创建了一个.cer文件和.pfx文件,然后将其上载到.pfx中,以上传到cloudservice证书,将.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);

并且我正在检查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)错误的请求。

我哪里错了? 我听不懂 是关于方法参数还是错误的上传证书?

你有什么估计吗?

谢谢。

我解决了我的问题。

这与认证无关,首先获得生产配置文件,然后更改它的当前实例数并重新部署。

这是代码:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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