Share via


Deleting a Container Using SOAP

[This document supports a preliminary release of a software product that may be changed substantially prior to final commercial release. This document is provided for informational purposes only.]

To delete a container, the container being deleted must be in scope. This is done by creating a Scope object and setting its AuthorityId and ContainerId property values.

using (SitkaSoapServiceClient proxy = new SitkaSoapServiceClient("EndPointName"))
{
proxy.ClientCredentials.UserName.UserName = username;
proxy.ClientCredentials.UserName.Password = password;
// Set scope to the container you want to delete
Scope myContainerScope = new Scope();myContainerScope.AuthorityId = "MyAuthorityId";myContainerScope.ContainerId = "MyContainerId";
// Delete container that is in scope.
proxy.Delete(myContainerScope);
}

When a container is deleted, all the entities beneath it are also deleted. The following example first creates a sample container and then deletes it. To create a working sample,

  • Add a service reference. For detail steps, see Examples of Using SOAP Interface with the SQL Data Services.
  • Update the code and provide existing authority id, and new container id.
  • Provide credentials (user name, password) when application executes.
  • In the code below, the "using DeleteContainerUsingSOAP.ssdsClient" statement has two parts:
    • The first part (DeleteContainerUsingSOAP) is the namespace name. This namespace name must match the Default namespace of the application.
    • The second part (ssdsClient) is the name you provided when you added the service reference.
using DeleteContainerUsingSOAP.ssdsClient;
using System.Collections.Generic;
using System;
using System.ServiceModel;
using System.Text;

namespace DeleteContainerUsingSOAP
{
    class Program
    {
        // Provide your own values for these member variables
        private static string userName;
        private static string password;
        private const string authorityId = "<YourExistingAuthorityId>";
        private const string containerId = "<SampleContainerIdToCreate>";
        private static SitkaSoapServiceClient proxy = null;

        static void Main(string[] args)
        {
            Console.Write("Username: ");
            userName = Console.ReadLine();
            Console.Write("Password: ");
            password = ReadPassword();

            using (proxy = new SitkaSoapServiceClient("BasicAuthEndpoint"))
            {
                try
                {
                    proxy.ClientCredentials.UserName.UserName = userName;
                    proxy.ClientCredentials.UserName.Password = password;

                    // Create a test container (to be deleted below)
                    CreateContainer();

                    // Now delete that container
                    // Identify scope. Scope identifies container to be deleted.
                    Scope myContainerScope = new Scope();
                    myContainerScope.AuthorityId = authorityId;
                    myContainerScope.ContainerId = containerId;

                    proxy.Delete(myContainerScope);

                    Console.WriteLine("Container {0} deleted!", containerId);
                }
                catch (FaultException<Error> e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (CommunicationException e)
                {
                    Console.Write(e.Message);
                }
            }
        }

        static void CreateContainer()
        {
            // Identify scope. It identifies authority where container will be added.
            Scope myAuthorityScope = new Scope();
            myAuthorityScope.AuthorityId = authorityId;

            // Add sample containter - to be deleted by this app.
            Container c1 = new Container();
            // Set metadata properties
            c1.Id = containerId;
            proxy.Create(myAuthorityScope, c1);

            Console.WriteLine("Container {0} created!", c1.Id);

        }

        private static string ReadPassword()
        {
            StringBuilder retval = new StringBuilder();
            ConsoleKeyInfo keyInfo;
            while ((keyInfo = Console.ReadKey(true)).Key != ConsoleKey.Enter)
            {
                Console.Write("*");
                retval.Append(keyInfo.KeyChar);
            }
            Console.WriteLine();

            return retval.ToString();
        }
    }
}

To verify that the container was deleted, enter the URI of the container in the Web browser. If the container was deleted, you will get the appropriate "not found" error.

https://<authority-id>.data.database.windows.net/v1/<container-id>

You can also specify an empty query with the authority in the scope. This query returns all the containers in the specified authority. For details about queries, see Querying SQL Data Services.

https://<authority-id>.data.database.windows.net/v1?q=''

See Also

Concepts

Getting Ready to Use SQL Data Services
SDS Data Model Overview (Authorities, Containers, Entities and Flexible Entities)
Examples of Using SOAP and REST Interfaces with the SQL Data Services
Creating a Container Using SOAP
Deleting a Container Using REST