Creating an Authority 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.]
As described in SDS Data Model Overview (Authorities, Containers, Entities and Flexible Entities), you can create one or more authorities in the service and store containers beneath it. To create an authority, the service must be in scope. This is done by creating scope
object without specifying any specific authority, container, or entity ids. This is also referred as the "empty" scope.
using (SitkaSoapServiceClient proxy = new SitkaSoapServiceClient("endPointName"))
{
proxy.ClientCredentials.UserName.UserName = "username";
proxy.ClientCredentials.UserName.Password = "password";
// To target the "service" level you use the "empty" scope.
Scope serviceScope = new Scope();
// Create authority
Authority auth = new Authority();
auth.Id = "books-docsamples";
proxy.Create(serviceScope, auth);
}
Note
The authority id must contain only lowercase letters, numbers, or dashes.
The following C# code creates an 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 unique authority id
- Provide credentials (user name, password) when application executes.
- In the code below, the "
using CreateAuthorityUsingSOAP.ssdsClient"
statement has two parts:- The first part (
CreateAuthorityUsingSOAP
) 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.
- The first part (
using System;
using CreateAuthorityUsingSOAP.ssdsClient;
using System.ServiceModel;
using System.Text;
namespace CreateAuthorityUsingSOAP
{
class Program
{
// Provide your own values for these member variables
private static string userName;
private static string password;
private const string sampleAuthorityId = "<AuthorityIdToCreate>";
static void Main(string[] args)
{
Console.Write("Username: ");
userName = Console.ReadLine();
Console.Write("Password: ");
password = ReadPassword();
// SitkaSoapEndPoint is endpoint name - from app.config file
using (SitkaSoapServiceClient proxy = new SitkaSoapServiceClient("BasicAuthEndpoint"))
{
proxy.ClientCredentials.UserName.UserName = userName;
proxy.ClientCredentials.UserName.Password = password;
// To target the whole service (i.e. the place where we create
// authorities, use an empty scope.
Scope serviceScope = new Scope();
Authority auth = new Authority();
auth.Id = sampleAuthorityId;
try
{
proxy.Create(serviceScope, auth);
Console.WriteLine("Authority {0} created!", auth.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("Authority {0} already existed", auth.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 that the authority was created, enter the authority URI in the browser.
https://<NewAuthorityId>.data.database.windows.net/v1/
Note
When querying for non-blob entities your browser need to be aware of the application/x-ssds+xml
SSDS content type. For Internet Explorer this can be done by adding a new key in the registry. For more information, see Guidelines and Limitations.
It returns authority metadata created as shown in the following sample XML:
<s:Authority 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>NewAuthorityID</s:Id>
<s:Version>version-number</s:Version>
</s:Authority>
See Also
Concepts
Guidelines and Limitations
Creating a Container Using SOAP
Creating an Authority Using REST
SDS Data Model Overview (Authorities, Containers, Entities and Flexible Entities)