问题描述
我可以使用Azure管理库扩展Azure Web应用程序/API应用程序吗?我基本上想实现Web应用程序的放大和缩小以处理限制.因此,我需要通过C#代码扩展Web应用程序和api应用程序.任何指向任何适当的库/ReST API的指针?
Can I scale azure web apps/api apps using Azure Management libraries? I basically want to implement scaling up and down of web apps to handle throttling. Hence, I need to scale the web app and api apps via C# code. Any pointers to any apprpriate library/ ReST API?
借助下面提到的答案,我了解了如何更新APP Service计划以进行横向扩展,但是,我无法找到我的APP Service的webHostingPlanName.我尝试使用以下代码,托管计划始终总是为空.
With teh help of the answer mentioned below, I understand how to update the APP Service plan to scale out, however, I am not able to find webHostingPlanName for my APP Service. I tried with the below code, and hosting plan always comes out to be null.
var regionName = "myregion";
var credentials = GetCredentials();
var websiteManagementClient = CloudContext.Clients.CreateWebSiteManagementClient(credentials);
var webSpaces = websiteManagementClient.WebSpaces.List();
var webSpace = webSpaces.FirstOrDefault(x => x.GeoRegion == regionName);
if (webSpace == null)
{
throw new Exception(string.Format("No webspace for region {0} found", regionName));
}
var webHostingPlans = websiteManagementClient.WebHostingPlans.List(webSpace.Name);
var webHostingPlan = webHostingPlans.FirstOrDefault();// this is null always, I know an APP service exists in this region
推荐答案
是的,我们可以使用Microsoft.WindowsAzure.Management.Websites库来缩放Web应用程序.使用方法WebSiteManagementClient.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters)
来实现它.
Yes, We can use Microsoft.WindowsAzure.Management.Websites library to scale up and down of web apps.Using method WebSiteManagementClient.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters)
to implement it.
我已经做了一个演示来做到这一点.以下是我的详细步骤:
I had done a demo to do this. The following are the my detail steps:
1.安装Microsoft.WindowsAzure.Management.WebSites,我们可以从链接.
1.Install the Microsoft.WindowsAzure.Management.WebSites that we can get it from the link.
2.创建WebsiteManagementClient对象.
我使用证书创建了websitemagement客户程序.
I used the cert to create the websitemagement client.
-
在安装VS之后,使用makecert.exe在VS文件夹下创建证书.
Create a cert with makecert.exe that is under the VS folder after install the VS.
makecert -sky exchange -r -n "CN=[CertificateName]" -pe -a sha1 -len 2048 -ss My "[CertificateName].cer
- 上传.证书文件到Azure门户,然后获取指纹
3.使用代码生成WebsiteManagementClient对象
public static X509Certificate2 GetCert(string thumbprint)
{
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (certCollection.Count <= 0) return null;
X509Certificate2 cert = certCollection[0];
return cert;
}
var cert = GetCert(string thumbprint) var subscriptionId ="Your subscriptionId"var webSiteManagementClient = new WebSiteManagementClient(new CertificateCloudCredentials(subscriptionId, cert));
var cert = GetCert(string thumbprint) var subscriptionId ="Your subscriptionId"var webSiteManagementClient = new WebSiteManagementClient(new CertificateCloudCredentials(subscriptionId, cert));
4.构造WebHostingPlanUpdateParameters
var webHostingPlanUpdateParameters = new WebHostingPlanUpdateParameters
{
NumberOfWorkers = 1, //the number of the instances
SKU = SkuOptions.Standard,
WorkerSize = WorkerSizeOptions.Small
};
5.使用代码更新WebHostingPlans
client.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters);
这篇关于Azure网站扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!