Share via


Delete Storage Account

 

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 (OK) を返します。 状態コードについては、次を参照してください。 サービス管理のステータスとエラー コードします。

応答ヘッダー

この操作の応答には、次のヘッダーが含まれています。 応答には、追加の標準 HTTP ヘッダーがあります。 準拠している標準ヘッダーはすべて、 、http/1.1 プロトコル仕様します。

応答ヘッダー 説明
x-ms-request-id 管理サービスに対して行われた要求を一意に識別する値。 呼び出すことができます、非同期操作の 操作の状態を取得します。 操作が完了するかどうかを確認するヘッダーの値、失敗した、または進行中です。

応答本文

None です。

「解説」

使用して、 Delete Storage Account を名前によってストレージ アカウントを削除する操作。 削除したストレージ アカウントに格納されているデータを復元することはできず、他のユーザーによって削除されたストレージ アカウント名を適用することができます。

ストレージ アカウントを削除する前に、すべての OS イメージ、VM イメージ、およびアカウントに配置されているディスクをまず削除する必要があります。 非同期操作を使用して、ストレージ アカウントから成果物を削除します。 使用することができます、 操作の状態を取得します。 操作がストレージ アカウントを削除しようとする前に、操作が完了したことを確認します。 すべての操作がストレージ アカウントを削除する前に終了するには、最大で 15 分かかる場合があります。

使用例

次のサンプル プログラムは、サブスクリプション id、関連付けられている管理証明書のサムプリント、操作バージョン、およびストレージ アカウント名では、および呼び出し、 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: