Share via


Creating 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.]

An authority can store zero or more containers. Within an authority, each container id must be unique.SDS Data Model Overview (Authorities, Containers, Entities and Flexible Entities) To add a container an authority must be in scope. This is done by creating a scope object and setting its AuthorityId property value.

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

// Identify scope. To create a container authority must be in scope.
Scope myAuthorityScope = new Scope();myAuthorityScope.AuthorityId = authorityId;

// Create a container
Container c1 = new Container();
c1.Id = "NewContainerId";
proxy.Create(myAuthorityScope, c1);
…
}

The following C# example adds a container to your existing authority. To create a working sample,

  • Add a service reference. For detail steps, see Examples of Using SOAP Interface with the SQL Data Services.
  • Update code and provide existing authority id and new container id.
  • Provide credentials (user name, password) when application executes.
  • In the code below, the "using CreateContainerUsingSOAP.ssdsClient" statement has two parts:
    • The first part (CreateContainerUsingSOAP) 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 CreateContainerUsingSOAP.ssdsClient;
using System;
using System.Security.Cryptography;
using System.Text;
using System.ServiceModel;

namespace CreateContainerUsingSOAP
{
    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 = "<ContainerIdToCreate>";

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

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

                // Identify scope. To create a container you need to specify an authority scope.
                Scope myAuthorityScope = new Scope();
                myAuthorityScope.AuthorityId = authorityId;

                // Add a container
                Container c1 = new Container();
                // Set metadata property
                c1.Id = containerId;

                try
                {
                    proxy.Create(myAuthorityScope, c1);

                    Console.WriteLine("Container {0} created!", c1.Id);
                }
                catch (FaultException<Error> e)
                {
                    // Suppress EntityExists errors in case user and/or authority already exists
                    if (e.Detail.StatusCode != ErrorCodes.EntityExists)
                    {
                        Console.WriteLine("Error: {0}:{1}", e.Detail.StatusCode, e.Detail.Message);
                        Console.WriteLine(e);
                        return;
                    }
                    Console.WriteLine("Container {0} already exist. Creation failed", c1.Id);
                }
                catch (Exception e)
                {
                    Console.Write("Error: {0}", e.Message);
                }
            }
        }

        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 results, enter the container URI in the browser:

https://<YourExistingAuthorityId>.data.database.windows.net/v1/<NewContainerId> 

Note

When querying for non-blob entities your browser need to be aware of the application/x-ssds+xml SDS content type. For Internet Explorer this can be done by adding a new key in the registry. For more information, see Guidelines and Limitations.

Sample container metadata is shown below:

<s:Container xmlns:s="https://schemas.microsoft.com/sitka/2008/03/" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xmlns:x="http://www.w3.org/2001/XMLSchema">
  <s:Id>NewContainerId</s:Id>
  <s:Version>version-number</s:Version>
</s:Container>

You can specify an empty query with the specific authority in the scope to find all the containers in it. For details about queries, see Querying SQL Data Services.

https://<YourExistingAuthorityId >.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)
SDS Data Model Overview (Authorities, Containers, Entities and Flexible Entities)
Creating a Container Using REST
Examples of Using SOAP and REST Interfaces with the SQL Data Services
Creating an Authority Using SOAP
Guidelines and Limitations