Delete Storage Account 异步操作删除指定的存储帐户。
请求
Delete Storage Account 可能指定请求,如下所示。 替换 <subscription-id> 与您的订阅 ID 和 <service-name> 替换为存储帐户的名称。
| 方法 | 请求 URI |
|---|---|
| 删除 | https://management.core.windows.net/<subscription-id>/services/storageservices/<service-name> |
必须确保向管理服务发出请求的安全性。 有关其他详细信息,请参阅 进行身份验证服务管理请求。
URI 参数
None。
请求标头
下表介绍请求标头。
| 请求标头 | 说明 |
|---|---|
x-ms-version |
必需。 指定要用于此请求的操作的版本。 此标头的值必须设置为 2011-06-01 或更高版本。 有关版本控制标头的详细信息,请参阅 服务管理版本控制。 |
请求正文
None。
响应
响应包括 HTTP 状态代码、 一组响应标头和响应正文。
状态代码
此操作成功后返回状态代码 200 (正常)。 有关状态代码的信息,请参阅 服务管理状态和错误代码。
响应标头
此操作的响应包括以下标头。 响应还可能包括其他标准 HTTP 标头。 所有标准标头都符合 HTTP/1.1 协议规范。
| 响应标头 | 说明 |
|---|---|
x-ms-request-id |
一个值,唯一标识针对管理服务发出的请求。 对异步操作,您可以调用 获取操作状态 标头以确定该操作已完成的值,已失败,或仍在进行。 |
响应正文
None。
备注
使用 Delete Storage Account 操作以按名称删除存储帐户。 不能恢复已删除的存储帐户中存储的数据,并已被删除的存储帐户名称可以采用其他用户。
在删除存储帐户之前,必须首先删除所有 OS 映像、 VM 映像和磁盘都位于该帐户。 异步操作用于从存储帐户中删除项目。 您可以使用 获取操作状态 操作,以确保已完成操作,然后再尝试删除存储帐户。 它可能需要 15 分钟完成,然后可以删除存储帐户的所有操作。
示例
下面的示例程序采用订阅标识符、 关联的管理证书指纹、 操作版本和存储帐户名称和调用 Delete Storage Account 操作,以删除该具名的存储帐户。 初始化 Version 常量用版本标头字符串, SubscriptionId 用该订阅的 GUID 标识符 Thumbprint 与你的管理证书指纹值和 ServiceName 替换为要被删除,若要运行此代码示例的存储帐户的名称。
using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
using System.Xml.Linq;
public class Program
{
// Set these constants with your values to run the sample.
private const string Version = "2011-10-01";
private const string Thumbprint = "management-certificate-thumbprint";
private const string SubscriptionId = "subscription-id-guid";
private const string ServiceName = "storage-account-name";
/// <summary>
/// Gets or sets the certificate that matches the Thumbprint value.
/// </summary>
private static X509Certificate2 Certificate { get; set; }
static void Main(string[] args)
{
try
{
Certificate = GetCertificate(Thumbprint);
DeleteStorageAccount(SubscriptionId, ServiceName);
Console.WriteLine("Storage Account {0} deleted.", ServiceName);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in Main:");
Console.WriteLine(ex.Message);
}
Console.Write("Press any key to continue:");
Console.ReadKey();
}
/// <summary>
/// Calls the Delete Storage Account operation in the Service Management
/// REST API for the specified subscription and storage account name.
/// Throws an ApplicationException on status code results other than OK.
/// </summary>
/// <param name="subscriptionId">The subscription identifier.</param>
/// <param name="serviceName">The name of the storage account to delete.</param>
private static void DeleteStorageAccount(
string subscriptionId,
string serviceName)
{
string uriFormat = "https://management.core.windows.net/{0}/services/storageservices/{1}";
Uri uri = new Uri(String.Format(uriFormat, subscriptionId, serviceName));
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = "DELETE";
request.Headers.Add("x-ms-version", Version);
request.ClientCertificates.Add(Certificate);
request.ContentType = "application/xml";
XDocument responseBody = null;
HttpStatusCode statusCode = HttpStatusCode.Unused;
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
// GetResponse throws a WebException for 4XX and 5XX status codes
response = (HttpWebResponse)ex.Response;
}
try
{
statusCode = response.StatusCode;
if (response.ContentLength > 0)
{
using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
{
responseBody = XDocument.Load(reader);
}
}
}
finally
{
response.Close();
}
if (!statusCode.Equals(HttpStatusCode.OK))
{
throw new ApplicationException(string.Format(
"Call to {0} returned an error:{1}Status Code: {2} ({3}):{1}{4}",
uri.ToString(),
Environment.NewLine,
(int)statusCode,
statusCode,
responseBody.ToString(SaveOptions.OmitDuplicateNamespaces)));
}
return;
}
/// <summary>
/// Gets the certificate matching the thumbprint from the local store.
/// Throws an ArgumentException if a matching certificate is not found.
/// </summary>
/// <param name="thumbprint">The thumbprint of the certificate to find.</param>
/// <returns>The certificate with the specified thumbprint.</returns>
private static X509Certificate2 GetCertificate(string thumbprint)
{
List<StoreLocation> locations = new List<StoreLocation>
{
StoreLocation.CurrentUser,
StoreLocation.LocalMachine
};
foreach (var location in locations)
{
X509Store store = new X509Store("My", location);
try
{
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection certificates = store.Certificates.Find(
X509FindType.FindByThumbprint, thumbprint, false);
if (certificates.Count == 1)
{
return certificates[0];
}
}
finally
{
store.Close();
}
}
throw new ArgumentException(string.Format(
"A Certificate with Thumbprint '{0}' could not be located.",
thumbprint));
}
}
此示例程序将生成类似于以下结果 ︰
Storage Account myexamplestorage1 deleted.
Press any key to continue: