【发布时间】:2016-06-02 09:41:27
【问题描述】:
我在带有证书授权的 azure 管理 API 中的授权存在问题。使用 Microsoft.Azure.Management.Sql 时出现错误:“AuthenticationFailedInvalidHeader: Authentication failed。‘Authorization’标头以无效格式提供。”但是当我用几乎相同的代码使用 Microsoft.WindowsAzure.Management.Sql 时,一切正常,但这是这个库的旧版本。我需要更新的版本,因为旧的看起来不支持弹性池。
这项工作很好
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Management.Sql;
using Microsoft.WindowsAzure.Management.Sql.Models;
namespace Test2
{
class Program
{
private static ServerListResponse servers;
private static string _resourceGroupName = "xxx";
private static string subscriptionId = "xxx";
private static string certThumbprint = "xxx";
static void Main(string[] args)
{
X509Certificate2 cert = GetCertificate(certThumbprint);
SubscriptionCloudCredentials credentials = new CertificateCloudCredentials(subscriptionId, cert);
SqlManagementClient client = new SqlManagementClient(credentials);
servers = client.Servers.List();
Console.ReadKey();
}
}
}
这会产生错误
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Microsoft.Azure;
using Microsoft.Azure.Management.Sql;
using Microsoft.Azure.Management.Sql.Models;
namespace Test2
{
class Program
{
private static ServerListResponse servers;
private static string _resourceGroupName = "xxx";
private static string subscriptionId = "xxx";
private static string certThumbprint = "xxx";
static void Main(string[] args)
{
X509Certificate2 cert = GetCertificate(certThumbprint);
SubscriptionCloudCredentials credentials = new CertificateCloudCredentials(subscriptionId, cert);
SqlManagementClient client = new SqlManagementClient(credentials);
Task.Run(async () =>
{
servers = await client.Servers.ListAsync(_resourceGroupName);
}).Wait();
Console.ReadKey();
}
}
}
【问题讨论】:
-
请看这个:stackoverflow.com/questions/37570328/…。基本上,您将 Azure 资源管理器 API 与 Azure 服务管理 API 混合使用。