在此之前,我曾经发过一篇文章讲叙了如何利用Azure power shell team 提供的class library

而就在这篇文章发布之后不久,我又发现微软发布了一个preview 版本的Windows Azure Management Libraries For .NET Nuget package来帮助.NET 开发人员来更好的控制Auzre Platform。

相比power shell team使用的library, Windows Azure Management Libraries For .NET 将业务逻辑更好的划分了开来,同时也使用了最新的Async programing来替代.net 4.5之前非常流行的异步委托编程方式。

很明显,这个class library今后将融入Azure SDK 之中,成为替代.NET 程序员直接调用Azure Management REST API的最佳选择。

那么就让我们来了解一下如何使用这个libararies吧。

一、添加Nuget Packages到项目中

新建一个Console应用程序,打开Tools->Library pPackage Manager->Package Manager Console.

然后输入以下命令行来安装该package:

Install-Package Microsoft.WindowsAzure.Management.Libraries -Pre

接下来我们将通过几个示例来了解如何使用这个library,首先让我们来获取Azure portal下所有Host service 的名字吧!

二、利用Compute Management Client 获取Azure platform下所有Azure cloud service host Name

首先,我们需要登录以下链接来获取与Azure 平台交互所需的publishsettings file

https://manage.windowsazure.com/publishsettings/index?client=vs&schemaversion=2.0

打开Console程序创建如下代码

using Microsoft.WindowsAzure.Management.Compute;
using Microsoft.WindowsAzure.Management;
using Microsoft.WindowsAzure;
using System.Security.Cryptography.X509Certificates; namespace ListCloudServiceName
{
class Program
{
public const string base64EncodedCertificate = "<Your PublishSettings file ManagementCertificate property's Value>";
public const string subscriptionId = "<You Azure subscription id>"; static void Main(string[] args)
{
getAllCloudServicesName();
Console.ReadLine();
} public static void getAllCloudServicesName()
{
ComputeManagementClient client = new ComputeManagementClient(getCredentials());
var cloudServiceList=client.HostedServices.List();
foreach (var cloudService in cloudServiceList)
{
Console.WriteLine(cloudService.ServiceName);
}
} static SubscriptionCloudCredentials getCredentials()
{
return new CertificateCloudCredentials(subscriptionId,new X509Certificate2(Convert.FromBase64String(base64EncodedCertificate)));
}
}
}

  

将publishsetting中的 ManagementCertificate 属性的值与id属性的值分别填入上面代码之中。

这样一个简单的获取所有cloud Service name的程序就完成了。

这里调用的是client.HostedServices.List()方法, 这个方法是一个extension method。

微软把与Azure Management REST API对应的一些方法都写成了extension method方便我们的调用。

而且微软将不同的技术都做了层层划分,首先是dll分成了5个,然后再在dll内将不同的技术划分开来方便了不同的.net 开发人员来进行调用,更具有针对性了。

由于目前这个package 刚刚推出,并没有多少的文档来详细阐述如何使用这个它, 我会在之后的blog中,针对我日常常用的一些操作来进行阐述,希望更多.net 开发人员能够使用上这个非常不错的类, 从而结束不停的send http web request。。。

Azure Management API 之 利用 Windows Azure Management Libraries 来控制Azure platform的更多相关文章

  1. Windows Server: 将虚拟机迁移到 Azure (以阿里云为例)

    Azure 虚拟机能很容易地导出 vhd 并迁移到各种环境中,包含本地及云端环境,或者迁移至其他区域.这为开发.测试.扩展带来了极大的便利.本文以阿里云为例,阐述如何将Windows Server 的 ...

  2. C#码农的大数据之路 - 使用Azure Management API创建HDInsight集群

    Azure平台提供了几乎全线产品的API,可以使用第三方工具来进行管理.对于.NET更是提供封装好了的库方便使用C#等语言实现Azure的管理. 我们使用创建HDInsight集群为例来介绍使用C#管 ...

  3. [Windows Azure] Managing SQL Database using SQL Server Management Studio

    Managing Windows Azure SQL Database using SQL Server Management Studio You can use Windows Azure SQL ...

  4. 【Azure API 管理】解决API Management添加AAD Group时遇见的 Failed to query Azure Active Directory graph due to error 错误

    问题描述 为APIM添加AAD Group时候,等待很长很长的时间,结果添加失败.错误消息为: Write Groups ValidationError :Failed to query Azure ...

  5. Windows Azure Mangement API 之 更方便的使用Mangement API

    许多.Net 程序员在使用Azure Management API的时候都选择参考微软官方示例,通过创建HttpWebRequest来创建. 或者自己创建类库来封装这些API,使之调用起来更加方便. ...

  6. [Windows Azure] Using the Graph API to Query Windows Azure AD

    Using the Graph API to Query Windows Azure AD 4 out of 4 rated this helpful - Rate this topic This d ...

  7. Azure REST API (1) 前言

    <Windows Azure Platform 系列文章目录> 一.服务运行时API简介 微软的Windows Azure服务总线提供了一整套REST风格的API,其中包括服务运行时API ...

  8. 使用 Puppet 在 Windows Azure 中配备 Linux 和 Windows 环境

     发布于 2013-12-11 作者 Ross Gardler 微软开放技术有限公司 (MS Open Tech) 很高兴地宣布发行新的 Windows Azure Puppet 模块.通过这个模 ...

  9. Azure REST API (3) 使用REST API,操作Azure ARM VM

    <Windows Azure Platform 系列文章目录> 笔者之前遇到一个客户,需求是当发生某一个特定条件的时候,对多台Azure ARM VM执行开机或者关机操作,这个时候就需要使 ...

随机推荐

  1. svn bug

    Error:Can't find temporary directory:internal error 原因:服务器端,磁盘满了 repository and is not part of the c ...

  2. github搭建静态博客

    p { margin-bottom: 0.1in; line-height: 120% } 1. 创建Repository 创建一个与自己github用户名对应的Repository,例如:abc.g ...

  3. React Native 中 CSS 的使用

    首先声明,此文原作者为黎 跃春 React Native中CSS 内联样式 对象样式 使用Stylesheet.Create 样式拼接 导出样式对象 下面的代码是index.ios.js中的代码: / ...

  4. 一起来做webgame,《卡片魔兽》(一)基础战斗

    写在前面的话 这不是教程,只是博主在娱乐过程中的一些小结记录.博主水平有限,没有什么高级的东西,只是将一些小的知识点结合一下,做这么一个养成类型的卡片页面游戏(=.=!有点绕).做一个完整的游戏,涉及 ...

  5. ESXi 5.5开启并配置SNMP

    1. 安装vshpere cli 2.设定SNMP通讯字并开启SNMP功能 进入到bin目录. C:\Program Files (x86)\VMware\VMware vSphere CLI\bin ...

  6. 数据结构与算法分析C++表述第二章编程题

    把昨天看的第二章巩固一下,做一做编程习题. 2.6: 第一天交2元罚金,以后每一天都是前一天的平方,第N天罚金将是多少? 这个题目和2.4.4-3介绍的幂运算基本一致.若按相同的递归思路分析,比那个问 ...

  7. sys.stdout.write与sys.sterr.write(二)

    目标: 1.使用sys.stdout.write模拟火车道轨迹变化过程 2.使用sys.stderr.write模拟火车道轨迹变化过程 1.sys.stdout.write模拟火车道轨迹变化 代码如下 ...

  8. CORS浏览器跨域

    在SO上发现一个解释跨域很棒的,忍不住拿过来 链接在此:http://stackoverflow.com/questions/10636611/how-does-access-control-allo ...

  9. windows下面配置apache+http

    一.apache安装 下载并安装apache_2.2.9-win32-x86-openssl-0.9.8h-r2.msi(见附件),找到apache安装目录(C:\Program Files (x86 ...

  10. SQL优化----百万数据查询优化

    百万数据查询优化 1.合理使用索引 索引是数据库中重要的数据结构,它的根本目的就是为了提高查询效率.现在大多数的数据库产品都采用IBM最先提出的ISAM索引结构.索引的使用要恰到好处,其使用原则如下: ...