Using Windows Azure's SQL Data Services via SOAP

Posted: (EET/GMT+2)

 

If you are interested in Windows Azure development like I am, you might wish to learn how to get started with the SQL Data Services (SDS). First of all, you need to know about the Azure web portal. For SQL Data Services, the address is http://portal.ex.azure.microsoft.com/. This is where you create yourself a solution to access from code, and a password to access it.

Then, you need to learn that SDS supports two programming interfaces, REST and SOAP. My opinion is that the SOAP interface is easier to use for example from C#, and it's also easy to add a service reference to Visual Studio. Speaking of which, the WSDL address for SOAP calls is https://database.windows.net/soap/v1/. With this address, Visual Studio is able to work out the rest.

SQL Data Services uses terminology such as authorities, containers and entities. You can create, read and delete these using the SOAP interface. For instance, to create a new authority, use the following code:

SitkaSoapServiceClient soapClient =
  new SitkaSoapServiceClient("BasicAuthEndpoint");
soapClient.ClientCredentials.UserName.UserName = "solution_name";
soapClient.ClientCredentials.UserName.Password = "P@ssw0rd!";

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

Here's an example of how to retrieve an entity with the ID string 12345:

Scope scope = new Scope();
scope.AuthorityId = "mynewauthority";
scope.ContainerId = "somecontainer";
scope.EntityId = "12345";

Entity readEntity = soapClient.Get(scope);
if (readEntity != null)
{
  string name = (string)readEntity.Properties["name"];
  string email = (string)readEntity.Properties["email"];
}

As you can see, accessing the SQL Data Services and the Azure cloud computing platform is easy. MSDN has more documentation. Check it out.