为什么调用Service Management API工作但调用Scheduler API失败?

时间:2013-11-06 21:12:09

标签: azure

我正在尝试拨打新的Azure Scheduler API。但是,我的所有请求都会返回此错误:

<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <Code>AuthenticationFailed</Code>
  <Message>The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.</Message>
</Error>

我很确定我的所有设置都正确,因为我可以使用相同的代码和证书拨打Azure Service Management API

我用于将证书附加到Web请求的代码来自MSDN Sample。我尝试制作的Scheduler API调用是Check Name Availability,Create Cloud Service和Create Job Collection。

我还验证了我的订阅处于活动状态以预览调度程序。

以下是我尝试过的请求示例:

Create Cloud Service

  

请求通过提交HTTP PUT操作来创建云服务   到Service Management API的CloudServices OData集合   Tenant.Replace与您的订阅ID和    使用您的云服务ID。

为此,我创建了一个指向以下内容的Web请求:

https://management.core.windows.net/ [MySubId] / cloudServices / [MyNewServiceName]

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri);

// Define the requred headers to specify the API version and operation type.
request.Headers.Add("x-ms-version", "2012-03-01");
request.Method = "PUT";
request.ContentType = "application/xml";

接下来,我按照文档中的说明添加请求正文:

<CloudService xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.microsoft.com/windowsazure'>
  <Label>[MyServiceName]</Label>
  <Description>testing</Description>
  <GeoRegion>uswest</GeoRegion>
</CloudService>

最后,我将我使用的证书添加到帐户中。

// Attach the certificate to the request.
request.ClientCertificates.Add(certificate);

我尝试获得响应,但我得到上面显示的错误。

BTW - 我也尝试过不同的地区,认为可能是区域问题,因为所有地区都不支持调度程序,但我仍然得到相同的响应。

1 个答案:

答案 0 :(得分:0)

您需要首先通过调用(PUT)注册调度程序:

<subscription id>/services?service=scheduler.JobCollections&action=register

如果要在.NET中执行此操作,可以使用新的管理库:

var schedulerServiceClient = new SchedulerManagementClient(credentials);
var result = schedulerServiceClient.RegisterResourceProvider();

Console.WriteLine(result.RequestId);
Console.WriteLine(result.StatusCode);
Console.ReadLine();

更多细节:http://fabriccontroller.net/blog/posts/a-complete-overview-to-get-started-with-the-windows-azure-scheduler/

相关问题