Steps to Enable Windows Azure Mobile Services

In this post we will take a step by step look on enabling Windows Azure Mobile Services in Windows Azure portal. To enable it login to Windows Azure Management Portal
After successful login to the portal in the bottom click on the New button.

 

image

On clicking of the NEW button under the COMPUTE tab, you need to select MOBILE SERVICES

image

You will get a screen with description of Mobile Services. Click on Try Now to enable Window Azure Mobile Services

image

In last step you will be prompted to select subscription and provide quick access token. However quick access token is optional.

image

In this way we can enable Windows Azure Mobile Services. I hope you find this post useful. Thanks for reading.

About these ads

Basic Operations on Windows Azure Table in Windows Azure Storage in Storage Client Library 2.0

In this post we will take a look on performing basic operations on Windows Azure table using Windows Azure Storage Client Library 2.0.

To work with Windows Azure Storage Client 2.0 grab the library from NuGet package. Right click on the project and select Manage NuGet Packages. In NuGet Package Manager and type WindowsAzure.Storage to search. Click on the Install to add library in the project.

image

After adding references of Windows Azure Storage Client Library version 2.0, you need to add following namespace

image

We can create a table as like following. Create an instance of CloudStorageAccount. To create this instance you need to pass StorageCredentials object. Second parameter in creating CloudStorageAccount is bollean value true. It says to use https connection while working with Windows Azure Storage account.

image

After creating object of storage account, we need to create instance of CloudTabaleClient, We can create that as following,

image

Last step in creating Azure Table is to take a reference of CloudTable and create it if not exist. Studenttable is name of the table, we are intended to create here.

image

A Table can be deleted as following

image

Consolidating all the above discussion we can create a table with HTTPS connection using Windows Azure Storage Client Library 2.0 is as following,


using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Table;
using System;

namespace AzureTableStorage
{
 class Program
 {
 static void Main(string[] args)
 {
 CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials("youraccountname", "youraccountkey"),true);
 CloudTableClient tableClient = account.CreateCloudTableClient();
 CloudTable table = tableClient.GetTableReference("Studenttable");
 table.CreateIfNotExists();
 }
 }

We are going to work with Studenttable. To represent entity of Studenttable let us create StudentEntity class as given in following code snippet. Make sure to inherit the class from TableEntity class.


public class StudentEntity : TableEntity
 {
 public StudentEntity()
 {
 PartitionKey= "Student";
 RowKey= Guid.NewGuid().ToString();
 }
 public double RollNumber { get; set; }
 public string Name { get; set; }
 public string Grade { get; set; }

}

We can insert an entity in table as following. Very first we need to create object of entity class or in other words need to create entity object to insert. We can create that as following,

image

Once entity to insert has been created next we need to create a TableOperationInsert. In the Insert function of TableOperation pass entity to be inserted. In this case studenttoInsert is the entity to be inserted hence passed as parameter. In last need to execute operation by passing it as input parameter of Execute function on instance of CloudTable.

image

Entity can be deleted by creating delete operation and executing it

image

In last let us consolidate all the discussions and full source code for working with Windows Azure table using Windows Azure Storage Client Library 2.0 is as following.

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Table;
using System;

namespace AzureTableStorage
{
 class Program
 {
 static void Main(string[] args)
 {
 // Creating Storage Account
CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials("youraccountname", "youraccountkey"),true);

//Creating Table Client
 CloudTableClient tableClient = account.CreateCloudTableClient();
 //Creating Table
 CloudTable table = tableClient.GetTableReference("Studenttable");
 table.CreateIfNotExists();
 //Creating Entity to insert
 var studenttoInsert = new StudentEntity
 {
 RollNumber = 1,
 Name = "Dhananjay Kumar",
 Grade = "Z"
 };

// Inserting an entity
 TableOperation operationToInsert = TableOperation.Insert(studenttoInsert);
 table.Execute(operationToInsert);
 Console.WriteLine("Student Entity Inserted ");
 Console.ReadKey(true);
 //Deleting an enitity
 TableOperation operationToDelete = TableOperation.Delete(studenttoInsert);
 table.Execute(operationToDelete);
 Console.WriteLine("Student Entity Deleted");
 Console.ReadKey(true);
 }
 }
}

I shall conclude this post by saying that we learnt how to perform basic operations on Windows Azure table using Windows Azure Storage Client Library 2.0. In further posts we will explore much more complex operations on Windows Azure table.

Error in installing Windows Azure Storage Client Library 2.0

To start working with Windows Azure Storage Client Library 2.0. I created a project and tried adding reference of Windows Azure Storage Client Library 2.0 using NuGet. When I tried installing, I got following error message.

“Microsoft.Data.OData could not be resolved”

image

This error message is clearly saying that you need to install Microsoft.Data.OData version greater than 5.0.2 to install Windows Azure Storage Client Library 2.0. To install this in NuGet Manager Package dialog search Microsoft.Data.OData and install it.

image

After installing this you should able to install Windows Azure Storage Client Library version 2.0 via NuGet. I hope you find this post useful. Thanks for reading.