March 3, 2021
Hot Topics:

Is Azure the New Silver Lining?

  • By Jani Järvinen
  • Send Email »
  • More Articles »

With the solution created and a Visual Studio project in place, it is time to code. The SQL Data Service uses three important terms that you have to familiarize yourself with. First, an authority is a collective name for data that belongs to a database. A solution has one or more authorities. Each authority in turn can contain one or more containers; you could use them to relate to tables in regular SQL databases.

The "records" in SQL Data Services are called entities. But unlike in traditional SQL tables, entities do not have to be of a certain type; instead, entities store their values in properties. Properties are simply name/value pairs, where the value can be any object type you choose. Each entity has an identifier (a string) that you can also freely specify.

With the SOAP interface object, creating authorities and containers is the first step. For instance, you might write an application like that shown in Figure 8. The following code creates an authority with the given name "abc":

private void createAuthorityButton_Click(object sender,
   EventArgs e)
   SitkaSoapServiceClient soapClient = GetSoapClient();

   Scope scope = new Scope();
   Authority auth = new Authority();
   auth.Id = "abc";
   soapClient.Create(scope, auth);

   MessageBox.Show("Authority created!");

Figure 8: The SQL Data Services sample application.

Notice how the word "Sitka" appears in the name of the web service interface. The GetSoapClient method is a custom method helping to create the SOAP client object and set access credentials. To create an authority, you need to define a scope object that is defined as part of the service interface. In this case, the scope needs no special settings. The authority object must have an unique name; this can be read from a simple text box in the example application. Then, creating the authority is a matter of a simple web service method call called Create.

Here is how getting the SOAP client object could be implemented:

private SitkaSoapServiceClient GetSoapClient()
   SitkaSoapServiceClient soapClient =
      new SitkaSoapServiceClient("BasicAuthEndpoint");
   soapClient.ClientCredentials.UserName.UserName =
   soapClient.ClientCredentials.UserName.Password =
   return soapClient;

Notice how the constructor of the SOAP client specifies an endpoint named "BasicAuthEndpoint". The SOAP interface supports different authentication modes, and the easiest mode is the basic authentication mode. In this mode, setting the username and password is just a matter of assigning properties. As you will recall, you will get these credentials from the Azure web portal. The username is the name of the solution, for instance my_test.

Here is an example of creating a custom "personData" entity:

private void createEntityButton_Click(object sender,
   EventArgs e)
   SitkaSoapServiceClient soapClient = GetSoapClient();

   Scope scope = new Scope();
   scope.AuthorityId = authorityTextBox.Text.Trim();
   scope.ContainerId = containerTextBox.Text.Trim();
   Entity entity = new Entity();
   entity.Id = entityIdTextBox.Text.Trim();
   entity.Kind = "personData";

   entity.Properties = new Dictionary<string, object>();
   entity.Properties.Add("name", "John Doe");
   entity.Properties.Add("email", "john@company.com");
   soapClient.Create(scope, entity);

   MessageBox.Show("Entity created!");

Note how the scope object is used to specify the correct authority and container. Of course, you must have previously created a container also. Without a container, there would not be any place to store the entities.

Page 5 of 6

This article was originally published on January 20, 2009

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date