public static CertificateCloudCredentials FromPublishSettingsFile(string path, string subscriptionId)
{
try
{
var profile = XDocument.Load(path);
var certificate = new X509Certificate2(
Convert.FromBase64String(profile.Descendants("PublishProfile").First()
.Attribute("ManagementCertificate").Value));
return new CertificateCloudCredentials(subscriptionId, certificate);
}
catch (Exception ex)
{
throw ex;
}
}
使用此代码块从 Publish Settings 文件创建类型为 CertificateCloudCredentials 的对象。成功创建对象后,使用以下代码块创建 computeManagementClient。
var computeManagementClient = new ComputeManagementClient(creds);
尽管计算管理客户端仅接受 SubscriptionCloudCredentials,但 CertificateCloudCredentials 是兼容的,将被接受。