11

I would like to manage my Azure Cloud Services programmatically.

I am aware of the REST API but I am wondering if the is a native C# API available just like there is with Azure Storage.

REST API - Operations on Hosted Services: http://msdn.microsoft.com/en-us/library/windowsazure/ee460812.aspx

Or do I need to wrap the REST API myself as described in the post below?

Azure - Cannot programmatically perform VIP Swap: Azure - Cannot programmatically perform VIP Swap

Thanks.


Edit:

The CSManage suggestion helped me a lot.

You can reuse the ServiceManagement project and write your own client (instead of CSManage).

Use the ServiceManagementHelper to setup a channel to execute the commands.

Example:

    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

4 に答える 4

3

As of October 2013 there is a set of C# libraries that wrap the Windows Azure Service Management REST API.

It's available in nuget under the package name Microsoft.WindowsAzure.Management.Libraries.

The blog posts here and here give a bit of an overview and the documentation can be found on MSDN.

As the question asks, these libraries allow you to manage services (create deployments, scale deployments, perform vip swaps etc.) rather than interact with blob / table storage.

于 2014-08-14T08:06:12.473 に答える
1

I've had a very similar requirement and unfortunately there is no wrapper that lets you do this, the one mentioned in the other answer only has table/blob/queue support.

However there is a neat solution called csmanage, it's a command prompt application that uses the REST API under the hood lets you manage pretty much anything on Azure; you can view the source and see how it's done and how to implement it yourself.

Link to CSManage on MSDN

Word of warning: it's quite a task to grasp the flow of the application but once you get going, it gets easier.

Hint: Have a look at CSManageCommand.cs on line 104 is where the magic starts to happen, they're using WCF to communicate with the API which you can see in app.config.

If you're looking to use certain known command you can see they're presented in the following classes:

enter image description here

于 2012-11-21T14:29:05.687 に答える
1

You might also look at the Azure Fluent Management Library. There is a NuGet package available.

于 2013-05-24T12:26:34.603 に答える
-2

Yes, there is a Windows Azure API for C# and .NET.

You can find their Github page here and documentation here.

于 2012-11-21T14:16:27.323 に答える