使用新的Windows Azure SDK for .NET,我想获得所有虚拟机的列表。
拼凑早期的文档,这就是我想出的:
// This is a custom cert I made locally. I uploaded it to Azure's Management Certificates and added it to my local computer's cert store, see screenshot below.
X509Certificate2 myCustomCert = await this.GetAzureCert();
var credentials = new CertificateCloudCredentials(mySubscriptionId, myCustomCert);
using (var cloudServiceClient = CloudContext.Clients.CreateCloudServiceManagementClient(credentials))
{
credentials.InitializeServiceClient(cloudServiceClient); // Is this required? The next call fails either way.
// This line fails with exception: "The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription."
var services = await cloudServiceClient.CloudServices.ListAsync(CancellationToken.None);
}
我的第一个想法是证书不好,但我能够使用我的自定义证书成功调用 Azure REST API。正如您在下面看到的,它已正确添加到 Azure 管理证书并与我的订阅相关联:
我究竟做错了什么?