Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Archive for the ‘Azure’ Category

Create Table in Storage Account

Posted by Paul on November 6, 2011

In this article we can explore the table creation in storage account.

As a refresh, I would like to repeat that there are 3 types in Azure Storage

  • Blob
  • Table
  • Queue

The Blob creation was explored in the previous article. Table creation will be explored here.

Concepts in Table

Following are the key concepts in table.

  • Tables allow structure data storage
  • There can be 0..n tables in a storage account
  • Table store data as a collection of entities
  • Entity have a primary key and properties as key value pair

Note: The table we discuss here is not entirely same as our database table. The database table will be discussed in SQL Azure. In Blob Service, the data is stored in containers. But in Table Service, data is stored in tables.

The steps involved in creating a table are following:

Step 1:Create new project

As always create a new azure project and add a web role into it. Now add reference to the StorageClient dll file.

clip_image002

Step 2: Define the Entity

Now we need to define the entity with the required properties, create a new class, derive it from TableStorageEntityand define the following properties in it.

Our entity class is derived from TableStorageEntitybecause this class takes care of the key properties like PartitionKey, RowKey and necessary attributes.

Step 3: Code Part

Now we can write the code to do the following activities:

  • Do account authentication
  • Create Table client
  • Create table in account
  • Add the new entity to tabl

The following code performs the following:

protected void Page_Load(object sender, EventArgs e)

{

StorageCredentialsAccountAndKey accountAndKey = new

StorageCredentialsAccountAndKey("youraccount", "key");

CloudStorageAccount account = new CloudStorageAccount(accountAndKey, true);

CloudTableClient client = account.CreateCloudTableClient();

client.CreateTableIfNotExist("Contact");

TableServiceContext tableContext = new

TableServiceContext(account.TableEndpoint.ToString(),

account.Credentials);

Contact contact = new Contact();

contact.PartitionKey = "1";

contact.RowKey = "1";

contact.Name = "Contact1";

contact.Address = "Address1";

tableContext.AddObject("Contact", contact);

tableContext.SaveChanges();

}

The account name and key can be obtained as explained in the previous article.

Note: We are setting the PartitionKey and RowKey as “1” for demo purposes. The PartitionKey represents the partition identifier where the table is stored. The RowKey should be the unique identifier to the entity. More Info

The classes involved for resembles the ADO.NET Entity Framework classes.

Step 4: Viewing the entity inserted

You can use the Server Explorerto see the new entity inserted as shown below.

clip_image004

Summary

In this article we have seen how to define a table and insert entity into it.

Advertisements

Posted in Azure | Tagged: , , , | Leave a Comment »

Create Blob in Storage Account

Posted by Paul on November 6, 2011

In this article we are trying to create the blob in the real storage account we created. As we are aware of the basics of blob and related classes in Windows Azure this article is emphasizing on the storage account related activities.

The core classes involved in Winows Azure blob activities were:

· CloudStorageAccount

· CloudBlobClient

· CloudBlobContainer

· CloudBlob

Connecting to the Storage Account

For connecting to the storage account, we need the correct Account Name and Key.

For obtaining the account name do the following:

  • Sign in to Windows Azure Portal
  • Click the Hosted Services group from left pane
  • Click the Storage Accounts from left pane
  • Select the account we created previously
  • From the right pane you can get the Name of the account

clip_image002

For obtaining the key do the following:

  • Click on the View button of Primary access key
  • On the appearing dialog click the copy button and you are ready with the key

clip_image004

Note In the above dialog we can see Primary access key and Secondary access key. Both can be used for the account authentication purpose. The secondary access key is used for making the application available during change in primary access key. You can read about it here

Modify the Account Access Code

We have to modify the account specification code as given below.

StorageCredentialsAccountAndKey accountAndKey = new StorageCredentialsAccountAndKey(“account”, “primarykey”);

CloudStorageAccount account = new CloudStorageAccount(accountAndKey, true);

Use your account name and the key in the account and primarykey texts.

Now the code is ready for connecting to the online storage account

Execute the Code

Now you can execute the code and view the result in browser as shown below.

clip_image006

If you can see the file name you have uploaded, then the online connection to storage account is success.

Using the Server Explorer for viewing Blobs

Visual Studio provides a convenient way to see the blobs we have uploaded. For viewing them use the View > Server Explorer command.

clip_image008

In the above dialog, right click on Windows Azure Storage tree item.

clip_image010

In the above dialong, click on the Add New Storage Account menu item.

Specify the account credentials in the appearing dialog.

clip_image012

Click the Ok button to continue.

A new tree item with your Account Name will be created and expanding that you can access your blob and container. Click on the container and a new view is opened showing the list of files in the container.

clip_image014

In the above window you can see the File.txt blob item you have created. This confirms the creation of blob in online storage account.

Summary

In this article we have seen how to connect to the online storage account and create blobs. The Server Explorer helps in viewing the blobs created.

Posted in Azure | Tagged: , , | Leave a Comment »

Create Blob in Storage Emulator

Posted by Paul on November 6, 2011

In this article we are trying to create a blob in the storage emulator. The same blob creation can be done on storage account too.

Some Theories on Blob in Azure

  • Blob represents Binary Large Object
  • It can contain text and binary data
  • Containers are required for storing Blobs
  • Containers can be private and public
  • Blob can have metadata

The storage account created should be having containers for storing blobs. The containers can be viewed as folders.

Eg: Documents, Images etc.

The private containers are private to the storage account and only the account holder can access it. The urls in public containers are accessible over the internet.

The Blob can have metadata as collection of key value pair. We can store the information like Author, Date, and Description etc. for the blob.

Advantages of Blob

The blob helps us to store image files, documents etc. which are normally unstructured data. If the same is stored in database, it results in performance problems.

Without a blob service, the manual programming requires much effort to manage the large sized files.

The activities include:

  • Creating a File/Folder infrastructure in the web application space
  • Create with multipart uploads for uploading large files
  • Create a database table for managing the metadata
  • Create the corresponding entities
  • Manage with backup and restore of the large files involving high network traffics

Thanks to Microsoft, the blob service does all the things for us at a lower cost.


Steps in creating Blob

Following are the steps in creating a blob.

clip_image002

The first step (Create Storage Account) was already done from our side and we need to proceed with the further steps to create the blob.

There are two ways of creating container and blob

  • Through Program
  • Using Windows Azure Management Tool

In this article we are proceeding with the first way and the second way will be discussed in another upcoming article.

Following are the steps involved in the creation of container and blob.


Step 1: Create new web azure project

Create a new Windows Azure project and add a web role into it. The solution explorer would look like below.

clip_image004

Step 2: Add reference to library files

We need to add specific reference to the following Windows Azure SDK dll file.

Dll: Microsoft.WindowsAzure.StorageClient.dll

Location: C:\Program Files\Windows Azure SDK\v1.5\ref

clip_image006

Step 3: Create the container

Now open the code view of Default.aspx, place a label control on it and enter the following code.

protected void Page_Load(object sender, EventArgs e)

{

CloudStorageAccount account = CloudStorageAccount.DevelopmentStorageAccount;

CloudBlobClient client = account.CreateCloudBlobClient();

CloudBlobContainer container = client.GetContainerReference("documents");

container.CreateIfNotExist();

CloudBlob blob = container.GetBlobReference("File.txt");

blob.UploadFile(Server.MapPath("~/File.txt"));

// show the blobs

Label1.Text = "Blobs inside container: <br>";

foreach (IListBlobItem item in container.ListBlobs())

Label1.Text += item.Container + " " + item.Parent.ToString() + " " +

item.Uri.ToString() + " <br>";

}

Note: The container name as documents. We need to ensure the name should be lowercase and additional restrictions. An invalid naming convention will throw exception StorageClientExceptionwith message “One of the request inputs is out of range.”

There are two methods in class CloudBlobContainer for creating the container.

  • Create()
  • CreateIfNotExist()

Using the CreateIfNotExist() method is advised as it won’t throw the exception if a container already exists with the given name.

Step 4: Create the blob file

In the web role project add a file named File.txtwith some text contents. Execute the application and you can see the following result.

clip_image008

Note: The local Storage Emulator is used in the above code for creating the container and blob. In the real scenario of uploading to online storage account, we need to modify the line:

clip_image010

as shown below

clip_image012

Summary

In this article we have learned some information on blob, container and how to create them programmatically. The associated source code can be used to test blob creation in your local machine.

Posted in Azure | Tagged: , , | Leave a Comment »

Create Storage Account

Posted by Paul on November 6, 2011

For storing in Windows Azure Storage we need to create a Storage Account. The advantages of storage account are following:

  • Exposed over HTTP, REST and OData
  • Permanent Data Storage
  • 3 Types of Storage: Blob, Table and Queues
  • Accessible from anywhere
  • Exposed to Pricing

Please remember that the previous Local Storage was temporary storage and only accessible inside the azure environment. So the Storage Account gains more advantages than local storage.

OData is the synonym for Open Data Protocol.

The data in the storage account is accessible from a mobile application, windows application or other web role.

For using the Windows Azure Storage, we need to create a Storage Account which is explained in step by step.

Step 1: Select the Storage Accounts item from portal

Sign in to the Windows Azure Portal and select the Storage Accounts link from the left pane. The order of clicks are depicted in the figure below.

clip_image002

Step 2: Click on the New Storage Account button

From the ribbon on top, click on the New Storage Account button as shown below

clip_image004

Step 3: Enter the details

On clicking the button from previous step, the following dialog box appears.

clip_image006

Enter the details for your account.

URL: The url should be unique and in lower case. The uniqueness prevents any duplicate url from other accounts.

Region: Choose a region closer to your location or the deployed application location so that the access will be faster.

After entering the details click the Ok button to continue

Step 4: Wait for Account Creation

Now there will be a delay due to the account creation, DNS configuration activities. Wait for a few minutes and you will be ready with the account as shown below.

clip_image008

Once the status changed to Created you are ready with the account. The account usage for storing blob, table and queues will be demonstrated in further articles.

Summary

In this article we have seen how to create a Storage Account through the Windows Azure Portal. This storage account is needed to use Windows Azure Storage types like tables, queues and blobs.

Posted in Azure | Tagged: , , | Leave a Comment »

Local Storage Example

Posted by Paul on November 6, 2011

In this article, we are trying to experiment the local storage feature of Windows Azure. From the previous article we found that local storage is one of the primitive storage mechanisms in Windows Azure.

The core features of Local Storage are:

  • Temporary Storage
  • Feature provided by the Operating System
  • Similar to Hard Drive
  • Exposed as logical file system
  • .Net Directory/File IO Framework used to access it
  • Can be used for storing Cache items

Creating a Local Storage

Here we are creating a local resource through the step by step activities.

Step1: Create new Web Role project

You will be familiar with web role creation and you can repeat the same. After the solution is created, the Solution Explorer will be looking like below:

clip_image002

Step 2: Open the local storage pane

Now double click on the WebRole1 item shown above to open the project configuration, Form there click the Local Storage pane item.

clip_image004

Step 3: Add a new Local Storage item

Add a new local storage items by clicking the Add Local Storage button. Rename it to TestStorage Change the Size to 10 MB as shown in the figure and save the configuration.

clip_image006

The above change will modify the configuration file of the application.

Step 4: Show Information about the Local Resource

Now we can place a label on the page, rename it to InfoLabel. Then on the page load event we can access the local resource and show the properties it has.

clip_image008

The RootPath property gives the current path of the resource in machine.

The MaximumSizeInMegabytes property returns the size allocated to it.

On executing the application we can see the following output.

clip_image010

Step 5: Start using the folder

Now we can use the above folder for our storage purpose. We can create folder, files inside it.

Create a new button on the page and name it as CreateFolderAndFileButton. On click of the button place the code to create a directory and file.

protected void CreateFolderAndFileButton_Click(object sender, EventArgs e)

{

LocalResource resource = RoleEnvironment.GetLocalResource(“TestStorage”);

Directory.CreateDirectory(resource.RootPath + “\\NewFolder”);

File.Create(resource.RootPath + “\\NewFile.txt”);

ShowContents(resource.RootPath);

}

private void ShowContents(string path)

{

InfoLabel.Text = “Directories inside it: <br>”;

foreach (string dir in Directory.GetDirectories(path))

{

InfoLabel.Text += dir + “<br>”;

}

InfoLabel.Text += “<br>Files inside it”;

foreach (string file in Directory.GetFiles(path))

{

InfoLabel.Text += file + “<br>”;

}

}

Execute the application and on clicking the button we can see the following output.

clip_image012

Summary

In this article we have found how to use the local storage feature of Windows Azure and creating folder and file inside it.

Posted in Azure | Tagged: , , , , | Leave a Comment »

Windows Azure – Storage Basics

Posted by Paul on November 6, 2011

In this article we are discussing Storage Accounts in Windows Azure. We will start with the purpose first.

What is the purpose of Storage Accounts?

We know that in our traditional applications we need persistence like:

  • Storing Data in Database
  • Storing Information in Files

The persistence is needed for retrieving them later. As the Windows Azure is a different platform (Operating System) the storage mechanisms also differ.

Types of Storage in Windows Azure

There are mainly three types of storage:

  • Local Storage
  • Windows Azure Storage
  • SQL Azure Database Storage

Local Storage

  • Similar to normal file system storage
  • Faster way of storing data
  • Used for Temporary purposes and data is removed on instance restart
  • Multiple application access is restricted
  • No price involved

Windows Azure Storage

  • Durable Storage service
  • Multiple application access is possible
  • Pricing involved
  • 3 Types of storage: Blobs, Tables and Queues

Sql Azure Database Storage

  • RDBMS (Relational Database Management System)
  • Sql Server on the Cloud
  • Access data using ADO.NET or ODBC technologies
  • Pricing involved

The following image summarizes the types of storage.

clip_image002

Each storage example will be provided in the further articles.

More Information

More information on the pricing and features can be found in link

Posted in Azure | Tagged: , , , | Leave a Comment »

Windows Azure – Moving Staging Deployment to Production

Posted by Paul on November 6, 2011

We can deploy a successful staging build to production, using the Swap VIP button in the Azure portal.

Step 1: Select the Deployment item

Sign in to the Azure Portal and select the appropriate item to deploy. In our case, the Deployment 1 is the item to be selected.

clip_image002

Step 2: Click on the Swap VIP

Click on the Swap VIP button from the top toolbar after selecting the deployment item. The following dialog box appear.s

clip_image004


Step 3: Click on the production url

Now the status of the deployment selected changes to Ready as shown below.

clip_image006

Click on the production url shown on the right pane to open the web role in a browser. The web role is shown below. Please note the url of the browser. The previous staging GUID urls are replaced by the production url.

clip_image008

Summary

That concludes the deployment from staging to production in the Windows Azure Portal. The web role is now deployed and available to the public.

More Information

The Swap VIP option does not actually deploy a new build. Instead, it will switch the production and staging builds by switching the DNS addresses internally. Thus the deployment seems to be faster as there is only switching of addresses internally.

Warning

The billing of the service will be there for both staging and production deployments. If the usage exceeds the trial limit charges will be levied on your credit card. Please take care. J

Posted in Azure | Tagged: , , | Leave a Comment »

Staging and Production Servers

Posted by Paul on November 6, 2011

Staging and Production Servers

In the previous article we have found how to deploy a new build to staging in Windows Azure. Now we need to move the staging build to production. Before that we are going to discuss the importance of staging and production servers.

Staging Environment

Staging environment will be having a configuration similar to the production environment. Before an application is released to production (where real users will be using), the application is test deployed to the staging environment. This gives us a chance to find potential bugs, security problems, configuration issues etc. It will save the team from entering into serious problems.

Production Environment

Production Environment will be the actual environment which the real users will be using. A build which was tested perfect in the staging environment is moved to the production environment.

The series of operation and the servers involved will be as following for a typical deployment. Typically, there will be a development machine where the application is created, deployed to a testing machine for the tester to find any bugs, deployed to staging and on successful validation deployed to Production server.

clip_image002


Summary

To summarize, we can say there are multiple machines involved in the development to deployment process.

  • Development Machine
  • Testing Machine
  • Staging Server
  • Production Server

Posted in Azure | Tagged: , , | Leave a Comment »

Windows Azure – WCF Hosting Methods

Posted by Paul on October 29, 2011

In the previous article we have experimented the ways of WCF hosting in Windows Azure. In this article I would like to summarize the important points of WCF service exposing in Windows Azure.

There are multiple ways of hosting WCF service in Windows Azure.

WCF Hosting

Description

Web Role

Hosted inside IIS with pooling and caching facilities

Worker Role

Self Hosted with more control

AppFabric

Self Hosting, Relayed connectivity through Service Bus

Let us examine them closely.

clip_image002

Method 1: Web Role Hosting

In the Web Role hosting, the WCF service is hosted inside IIS. This will give the advantages of IIS to the WCF service.

  • Identity Management
  • Recycling
  • Caching
  • Pooling
  • Logging


The Service creation will be much easier in this method as Visual Studio provides the templates for Service (.svc files). We need to create a new .svc file and place it in the web role project. The host names and ports are configured by the deployment and we can access the service through a browser.

The metadata end points are also automatically added. This saves a lot of amount of work from the developer side.

Method 2: Worker Role Hosting

Here the developer has to perform more work in creating the service contracts by defining the attributes in the contracts and implementation.

This method is advised if more control is needed over the service. We can easily configure the protocols in this way. In this case a corporate port has to be opened to expose the service while using the worker role.

Method 3: Hosting through AppFabric

In this method the WCF service is exposed through the Service Bus service feature of Windows Azure AppFabric. We can choose this option if we need to connect two disconnected applications.

This method is self hosted and more configurations needed. Here we can connect two disconnected applications using the Service Bus namespace. The namespace identifies the subscription and will be used for billing purposes on the cloud.

The Service Bus provides the following features:

  • Connectivity between disconnected applications
  • Higher Availability

Relay Service

There are two modes of connectivity in the Relay Service.

· TcpRelayConnectionMode.Relayed

· TcpRelayConnectionMode.Hybrid

The default mode is Relayed and here the service and client is connected through the relayed service.

Relayed Mode Connectivity

The following picture depicts the process in the Relayed mode.

clip_image004
The steps involved are following:

Step 1: The WCF Service authenticates and registers with the Relayed Service using the namespace and Provider keys.

Step 2: The Client authenticates with the Relay Service

Step 3: Client invokes a method using the Relay Service

Step 4: The Relay Service redirects the call to the registered WCF service.

Hybrid Mode Connectivity

In the Hybrid way of connectivity the client can communicate directly to the service. First the client connectivity starts as Relayed as usual and then if there is possibility of connecting directly to the service it will be provided.

Summary

In this article we have discussed the various WCF exposing methods in Windows Azure like web role, worker role and through AppFabric Service Bus.

Posted in Azure | Tagged: , , , | Leave a Comment »

Windows Azure – WCF Hosting Methods

Posted by Paul on October 29, 2011

In the previous article we have experimented the ways of WCF hosting in Windows Azure. In this article I would like to summarize the important points of WCF service exposing in Windows Azure.

There are multiple ways of hosting WCF service in Windows Azure.

WCF Hosting

Description

Web Role

Hosted inside IIS with pooling and caching facilities

Worker Role

Self Hosted with more control

AppFabric

Self Hosting, Relayed connectivity through Service Bus

Let us examine them closely.

clip_image002

Method 1: Web Role Hosting

In the Web Role hosting, the WCF service is hosted inside IIS. This will give the advantages of IIS to the WCF service.

  • Identity Management
  • Recycling
  • Caching
  • Pooling
  • Logging


The Service creation will be much easier in this method as Visual Studio provides the templates for Service (.svc files). We need to create a new .svc file and place it in the web role project. The host names and ports are configured by the deployment and we can access the service through a browser.

The metadata end points are also automatically added. This saves a lot of amount of work from the developer side.

Method 2: Worker Role Hosting

Here the developer has to perform more work in creating the service contracts by defining the attributes in the contracts and implementation.

This method is advised if more control is needed over the service. We can easily configure the protocols in this way. In this case a corporate port has to be opened to expose the service while using the worker role.

Method 3: Hosting through AppFabric

In this method the WCF service is exposed through the Service Bus service feature of Windows Azure AppFabric. We can choose this option if we need to connect two disconnected applications.

This method is self hosted and more configurations needed. Here we can connect two disconnected applications using the Service Bus namespace. The namespace identifies the subscription and will be used for billing purposes on the cloud.

The Service Bus provides the following features:

  • Connectivity between disconnected applications
  • Higher Availability

Relay Service

There are two modes of connectivity in the Relay Service.

· TcpRelayConnectionMode.Relayed

· TcpRelayConnectionMode.Hybrid

The default mode is Relayed and here the service and client is connected through the relayed service.

Relayed Mode Connectivity

The following picture depicts the process in the Relayed mode.

clip_image004
The steps involved are following:

Step 1: The WCF Service authenticates and registers with the Relayed Service using the namespace and Provider keys.

Step 2: The Client authenticates with the Relay Service

Step 3: Client invokes a method using the Relay Service

Step 4: The Relay Service redirects the call to the registered WCF service.

Hybrid Mode Connectivity

In the Hybrid way of connectivity the client can communicate directly to the service. First the client connectivity starts as Relayed as usual and then if there is possibility of connecting directly to the service it will be provided.

Summary

In this article we have discussed the various WCF exposing methods in Windows Azure like web role, worker role and through AppFabric Service Bus.

Posted in Azure | Tagged: , , , | Leave a Comment »