Exporteren (0) Afdrukken
Alles uitvouwen
EN
Deze inhoud is niet beschikbaar in uw taal, maar wel in het Engels.

Delete Storage Account

Updated: July 23, 2014

The Delete Storage Account asynchronous operation deletes the specified storage account.

The Delete Storage Account request may be specified as follows. Replace <subscription-id> with your subscription ID, and <service-name> with the name of the storage account.

 

Method Request URI

DELETE

https://management.core.windows.net/<subscription-id>/services/storageservices/<service-name>

You must make sure that the request that is made to the management service is secure. For additional details, see Authenticating Service Management Requests.

The following table describes the request headers.

 

Request Header Description

x-ms-version

Required. Specifies the version of the operation to use for this request. The value of this header must be set to 2011-06-01 or higher. For more information about versioning headers, see Service Management Versioning.

The response includes an HTTP status code, a set of response headers, and a response body.

A successful operation returns status code 200 (OK). For information about status codes, see Service Management Status and Error Codes.

The response for this operation includes the following headers. The response may also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.

 

Response Header Description

x-ms-request-id

A value that uniquely identifies a request made against the management service. For an asynchronous operation, you can call Get Operation Status with the value of the header to determine whether the operation is complete, has failed, or is still in progress.

Use the Delete Storage Account operation to delete a storage account by name. Data stored in a deleted storage account cannot be recovered, and storage account names that have been deleted can be adopted by other users.

Before you delete a storage account, you must first delete all OS Images, VM Images, and disks that are located in the account. Asynchronous operations are used to delete artifacts from a storage account. You can use the Get Operation Status operation to make sure that the operations are finished before you try to delete the storage account. It may take up to 15 minutes for all operations to finish before the storage account can be deleted.

The following example program takes the subscription identifier, an associated management certificate thumbprint, the operation version, and a storage account name, and calls the Delete Storage Account operation to remove the named storage account. Initialize the Version constant with a version header string, SubscriptionId with the GUID identifier for the subscription, Thumbprint with your management certificate thumbprint value, and ServiceName with the name of the storage account to be deleted to run the example code.

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 { getset; }
 
    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));
    }
}

This example program generates results similar to the following:

Storage Account myexamplestorage1 deleted.
Press any key to continue:

Weergeven:
© 2014 Microsoft