Windows Azure Management API 使用
来源:互联网 发布:java循环流程图 编辑:程序博客网 时间:2024/04/26 21:40
Windows Auzre平台可以通过后端代码就行azure platform的相关属性的修改, 这些API是基于REST service的,有GET,POST,PUT,DELETE几种方式,你可以参考MSDN的这篇文章来设置具体的URI和相关参数,比如subscription id,hosted service name,certificate等等:
Windows Azure Service Management REST API Reference
http://msdn.microsoft.com/en-us/library/windowsazure/ee460799.aspx
参考这篇文章,你需要做的就是根据里面的不同的section设置不同的Uri和参数。
例子,GET方式访问所有hosted service
string subscriptionID = "your azure subscription ID"; string thrumbnail = "your certificate thumbprint"; string hostedServiceName = "your hosted service name"; Uri requestUri = new Uri("https://management.core.windows.net/" + subscriptionID + "/services/hostedservices/" + hostedServiceName); X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.OpenExistingOnly); X509Certificate2Collection collection = store.Certificates.Find(X509FindType.FindByThumbprint, thrumbnail, false); store.Close(); if (collection.Count != 0) { X509Certificate2 certificate = collection[0]; HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(requestUri); httpRequest.ClientCertificates.Add(certificate); httpRequest.Headers.Add("x-ms-version", "2011-10-01"); httpRequest.KeepAlive = false; HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse; Stream stream = httpResponse.GetResponseStream(); using (StreamReader reader = new StreamReader(stream)) { Response.Write("a"); string s = reader.ReadToEnd(); Response.Write(s.Replace("<", "")); } httpResponse.Close(); stream.Close();
例子,POST方式修改hosted service配置信息
string subscriptionID = "your azure subscription ID"; string thrumbnail = "your certificate thumbprint"; string hostedServiceName = "your hosted service name"; string deployName = "staging"; Uri reuqestUri = new Uri("https://management.core.windows.net/" + subscriptionID + "/services/hostedservices/" + hostedServiceName + "/deploymentslots/" + deployName + "/?comp=config"); X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly); X509Certificate2Collection collection = store.Certificates.Find(X509FindType.FindByThumbprint, thrumbnail, false); store.Close(); if (collection.Count != 0) { X509Certificate2 certificate = collection[0]; HttpWebRequest request = HttpWebRequest.Create(reuqestUri) as HttpWebRequest; request.ClientCertificates.Add(certificate); request.Method = "POST"; request.ContentType = "application/xml"; request.Headers.Add("x-ms-version", "2010-10-01"); StringBuilder sb = new StringBuilder(); sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.Append("<UpdateDeploymentStatus xmlns=\"http://schemas.microsoft.com/windowsazure\">"); sb.Append(String.Format("<Status>{0}</Status>", "Suspended")); sb.Append("</UpdateDeploymentStatuscc>"); byte[] bytes = UTF8Encoding.UTF8.GetBytes(sb.ToString()); request.ContentLength = bytes.Length; HttpWebResponse response = request.GetResponse() as HttpWebResponse; using (Stream stream = request.GetRequestStream()) { stream.Write(bytes, 0, bytes.Length); } request.GetResponse(); }
subscription id是你的windows azure账号的ID, thumbprint是client端创建的自定义certificate的唯一标识符,同时你需要吧这个certificate上传到Azure management portal上面来,如果你需要在local的云模拟环境中测试的话,请在Role中配置好Certificate,如果只是运行web application或者Console application测试的话则不需要这一步,接着你就可以把Azure程序Publish到Management Portal上看效果了。
- Windows Azure Management API 使用
- Windows Azure 系列-- 使用Azure + Web API实现图片上传
- Windows Azure真实案例:Invensys Operations Management -公司使用Windows Azure AppFabric 实现动态节能的智能电网
- 使用Azure customvision api
- Windows Azure使用必读
- Windows Azure使用体验
- Windows Azure使用必读
- ACS被集成到了Windows Azure Management Portal中
- 现已可用:更新Updated Windows Azure SDK 和 Windows Azure Management的页面
- 使用SQL Server Management Studio连接SQL Azure
- Windows Azure入门教学系列 (七):使用REST API访问Storage Service
- Windows Azure入门教学系列 (八):使用Windows Azure Drive
- [Windows Azure] 使用 Windows Azure 快速搭建 Redis 服务器
- 使用 Azure Resource Manage JAVA API 管理 Azure 资源
- 使用python调用azure api步骤文档
- Windows Azure 系列-- Azure Redis Cache的配置和使用
- 使用 Azure PowerShell 管理 Azure 虚拟网络和 Windows 虚拟机
- 解决Azure Management API ForbiddenError: The server failed to authenticate the request
- 2012年云计算潜力股:开源PaaS平台
- struct sk_buff
- CreateFile用法和例子
- centos5.* 安装配置DNS 问题
- C++ 读写文件
- Windows Azure Management API 使用
- 【轻松学排序算法】眼睛直观感受几种常用排序算法
- Testin推移动互联网用户体验指数MUI,并免费提供真机监控服务
- oracle 优化语句 索引
- linux下which、whereis、locate、find 命令的区别
- HTTP协议是什么?
- C++程序如何获得自身路径(Qt源码)
- java中模拟鼠标和键盘操作
- 初级java开发人员应该掌握的知识