使用本机C#API管理我的Azure云服务?

时间:2012-11-21 14:13:34

标签: c# api rest azure

我想以编程方式管理我的Azure云服务。

我知道REST API,但我想知道它是否是可用的本机C#API,就像Azure存储一样。

REST API - 托管服务上的操作:http://msdn.microsoft.com/en-us/library/windowsazure/ee460812.aspx

或者我是否需要自己包装REST API,如下面的帖子所述?

Azure - 无法以编程方式执行VIP交换:Azure - Cannot programmatically perform VIP Swap

感谢。


修改

CSManage的建议给了我很多帮助。

您可以重用ServiceManagement项目并编写自己的客户端(而不是CSManage)。

使用ServiceManagementHelper设置通道以执行命令。

示例:

    public static string SubscriptionId { get; set; }
    public static string CertificateThumbprint { get; set; }

    public static X509Certificate2 Certificate { get; set; }

    private void button1_Click(object sender, EventArgs e)
    {
        SubscriptionId = ConfigurationManager.AppSettings["SubscriptionId"];
        CertificateThumbprint = ConfigurationManager.AppSettings["CertificateThumbprint"];

        X509Store certificateStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
        certificateStore.Open(OpenFlags.ReadOnly);
        X509Certificate2Collection certs = certificateStore.Certificates.Find(X509FindType.FindByThumbprint, CertificateThumbprint, false);
        if (certs.Count != 1)
        {
            MessageBox.Show("Client certificate cannot be found. Please check the config file. ");
            return;
        }
        Certificate = certs[0];

        // List Hosted Services
        var channel = ServiceManagementHelper.CreateServiceManagementChannel("WindowsAzureEndPoint", Certificate);
        var lhs = channel.ListHostedServices(SubscriptionId);
        foreach (HostedService hs in lhs)
        {
            MessageBox.Show(hs.ServiceName);
        }
    }

4 个答案:

答案 0 :(得分:3)

截至2013年10月,有一组C#库包装了Windows Azure Service Management REST API。

它在包名Microsoft.WindowsAzure.Management.Libraries下以nuget的形式提供。

博文herehere提供了一些概述,文档可以在MSDN找到。

正如问题所示,这些库允许您管理服务(创建部署,扩展部署,执行vip交换等),而不是与blob / table存储交互。

答案 1 :(得分:1)

我有一个非常相似的要求,遗憾的是没有包装器允许你这样做,另一个答案中提到的那个只有table / blob / queue支持。

然而,有一个称为csmanage的简洁解决方案,它是一个使用REST API的命令提示符应用程序,可让您管理Azure上的任何内容;你可以查看源代码,看看它是如何完成的以及如何自己实现它。

Link to CSManage on MSDN

警告语:掌握应用程序的流程是一项非常艰巨的任务,但一旦开始,它就会变得更容易。

提示:看看第104行的CSManageCommand.cs是魔术开始发生的地方,他们正在使用WCF与您在app.config中看到的API进行通信。

如果您希望使用某些已知命令,您可以看到它们出现在以下类中:

enter image description here

答案 2 :(得分:1)

您也可以查看Azure Fluent Management Library。有一个NuGet包。

答案 3 :(得分:-1)

是的,有一个用于C#和.NET的Windows Azure API。

您可以找到他们的Github页面here和文档here