Jean Paul's Blog

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

  • 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

Posts Tagged ‘azure’

Windows Azure – AppFabric Access Control Service Portal

Posted by JP on December 31, 2011

As part of the Access Control Service, we are performing the following in this article.

  • Create new Namespace
  • Using the Access Control Service Portal
  • Create new Identity Provider
  • Create new Rule Group

Creating the Namespace

For creating the namespace, sign in to the Windows Azure Management Portal. Open the Service Bus, Access Control & Caching item as shown below. (You can also use the previous namespace if it exists)

clip_image002

In the appearing window select the Access Control item from the left pane.

clip_image004

In the appearing dialog enter the required details. Please ensure the namespace is unique.

clip_image006

After entering the details click on the Create Namespace button to create the namespace. Wait for a few minutes and you will be ready with the new namespace Active as shown below.

clip_image008

The namespace accesscontrol2011 can be used in our next Access Control article involving programming.

Using the Access Control Service Portal

You can open the Access Control Service Portal by selecting the namespace and clicking on the Access Control Service button from the header panel as shown below.

clip_image010

(You can also access it using the url https://namespace.accesscontrol.windows.net)

On clicking the button we will get the window shown below:

clip_image012

We can configure the Identity Providers using the link on left. There is a default created Windows Live ID item inside it.

clip_image014

Create new Identity Provider

Now we can add a new identity provider Google. Click on the Add button to continue. The following page appears.

clip_image016

Select the option Google and click Next to continue.

clip_image018

Leave the default options and click Save to create the provider.

We can configure the Relying party applications using the link on left. There are no default entries inside it.

clip_image020

Now you can see the new identity provider in the list as shown below.

clip_image022

Create new Rule Group

Now we have to create a new rule group for our application. At least one rule group is needed for getting valid token from ACS.

Click on the Rule Groups item from the left pane and you will see the following screen.

clip_image024

Click on the Add button from the above screen.

clip_image026

In the above screen enter a name for the rule group and click the Save button and you will be getting the following screen.

clip_image028

Click on the Generate button to generate the rules automatically. The following screen will appear.

clip_image030

Select (check) the items Google and Windows Live ID and click the Generate button. You will get the following screen.

clip_image032

Check all the items as shown above and click the Save button. Your rule group will be created in the list as shown below.

Summary

In this article we have seen creation of namespace, adding identity providers and rule groups using the Access Control Service Portal. In the next article we can create a web role and test the providers.

Advertisements

Posted in C# | Tagged: , , , | Leave a Comment »

Windows Azure – AppFabric Access Control Service – Introduction

Posted by JP on December 21, 2011

In this article we can explore the Access Control service of Windows Azure AppFabric. As you know the services provided by AppFabric are shown below.

clip_image002

Theory on Access Control

The Access Control Service (ACS) provides a flexible way of authentication and authorization in the cloud premises. The ACS extracts out the authentication and authorization code outside the application.

We can use ACS along with:

  • Web Applications
  • Web Services

Simply, the Access Control Service 2.0 allows us to integrate single sign on (SSO) and centralized authorization into the web applications.

In the old applications we need to incorporate the authentication and authorization code inside our applications. This will lead to mixing of business logic with the security overheads. The PrincipalPermission attribute, Cookie Presence Checking etc. are some of the ways of doing it. AppFabric through ACS provides a better way of dealing with security aspects.

Protocols: The following protocols are supported by ACS 2.0

  • WS-Trust
  • WS-Federation
  • OAuth

Identity Providers: The identity providers supported by ACS include:

  • Windows Live ID
  • Facebook
  • Google
  • Yahoo
  • WS-Federation Identity Providers

Compatibility: ACS is compatible with web platforms including:

  • .Net
  • PHP
  • Java
  • Ruby
  • Python

Difference between Old Application and Azure Application Security Aspects

clip_image004

Service Namespace: Like the Service Bus, we need to create a service namespace for the Access Control Service too. The services in a particular namespace share the same DNS name. The Service Namespace acts as a top level partition around the end points.

There are different endpoints inside the namespace:

  • Security Token Service
  • Management Service
  • Management Portal
  • Service Metadata

The format of the end point will be:

https://<servicenamespace&gt;.accesscontrol.windows.net/mgmt

Managed Namespace: A managed namespace is partially managed by another service. The Service Bus and Cache services uses managed namespaces characterized by –sb and –cache respectively.

Relying Party: In the context of ACS, relying party is an application for which we are implementing federated authentication. The configuration includes a term Realm which acts as the URI. There is a Return Url which is invoked to provide the token when the invoker is valid.

Example of Realm are: http://contesso.com. Any request with Realm prefix with http://contesso.com will be gaining valid tokens. We can also include http://localhost/ as a valid realm.

We can also configure an Error url which will be invoked during any problems in the login process. Eg: http://www.yourdomain/error.htm

The configuration of relying party application can be manual or through program. The relying party control flow is depicted below.

clip_image006

Rule Groups: A relying party application should be associated with at least one rule group. If the Real match one configured application which is not associated with any of the rule groups, the token will not be issued.

We can associate one rule group with more than one application and one application with more than one rule group.

Summary

In this article we have learnt about the AppFabric Access Control Service. It provides a better way of authentication and authorization. In the next article we can see how to create a service namespace and using the Access Control Service Portal.

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

Windows Azure – BlockBlob PutBlock Method

Posted by JP on November 30, 2011

In this article we are discussing about uploading blob using PutBlock method. I would like to give a note that there are two types of blob in Windows Azure:

· Block Blob

· Page Blob

The Block Blob uploading is discussed here as Block Blobs are used for large file uploads. The associated code was developed to upload large files to Windows Azure Blob. The large file will be splitted into 4 MB chunks and then uploaded.

Method

Following are the important methods used:

· CloudBlockBlob.PutBlock()

· CloudBlockBlob.PutBlockList()

The PutBlock method is called for each 4MB file chunk and PutBlockList method is called at the end passing the file chunk ids.

Code

Following is the code of AzureBlobUtil.cs

public class AzureBlobUtil

{

private const int MaxBlockSize = 4000000; // Approx. 4MB chunk size

public Uri UploadBlob(string filePath, CloudStorageAccount account, string containerName)

{

byte[] fileContent = File.ReadAllBytes(filePath);

string blobName = Path.GetFileName(filePath);

return UploadBlob(fileContent, account, containerName, blobName);

}

public Uri UploadBlob(byte[] fileContent, CloudStorageAccount account, string containerName, string blobName)

{

CloudBlobClient blobclient = account.CreateCloudBlobClient();

CloudBlobContainer container = blobclient.GetContainerReference(containerName);

container.CreateIfNotExist();

CloudBlockBlob blob = container.GetBlockBlobReference(blobName);

HashSet<string> blocklist = new HashSet<string>();

foreach (FileBlock block in GetFileBlocks(fileContent))

{

blob.PutBlock(

block.Id,

new MemoryStream(block.Content, true),

null

);

blocklist.Add(block.Id);

}

blob.PutBlockList(blocklist);

return blob.Uri;

}

private IEnumerable<FileBlock> GetFileBlocks(byte[] fileContent)

{

HashSet<FileBlock> hashSet = new HashSet<FileBlock>();

if (fileContent.Length == 0)

return new HashSet<FileBlock>();

int blockId = 0;

int ix = 0;

int currentBlockSize = MaxBlockSize;

while (currentBlockSize == MaxBlockSize)

{

if ((ix + currentBlockSize) > fileContent.Length)

currentBlockSize = fileContent.Length - ix;

byte[] chunk = new byte[currentBlockSize];

Array.Copy(fileContent, ix, chunk, 0, currentBlockSize);

hashSet.Add(

new FileBlock()

{

Content = chunk,

Id = Convert.ToBase64String(System.BitConverter.GetBytes(blockId))

});

ix += currentBlockSize;

blockId++;

}

return hashSet;

}

public Stream DownloadBlobAsStream(CloudStorageAccount account, string blobUri)

{

Stream stream = new MemoryStream();

CloudBlobClient blobclient = account.CreateCloudBlobClient();

CloudBlockBlob blob = blobclient.GetBlockBlobReference(blobUri);

if (blob != null)

blob.DownloadToStream(stream);

return stream;

}

public string DownloadBlobAsFile(CloudStorageAccount account, string blobUri)

{

Stream stream = DownloadBlobAsStream(account, blobUri);

string fileName = "Blob.file"; // Please change file name based on your need

if (stream != null)

{

FileStream fileStream = File.Create(fileName);

stream.Position = 0;

stream.CopyTo(fileStream);

fileStream.Close();

return fileName;

}

return string.Empty;

}

}

internal class FileBlock

{

public string Id

{

get;

set;

}

public byte[] Content

{

get;

set;

}

}

Testing Code

For uploading blob into the container use the following code:

// Upload

Uri blobUri = _blobUtil.UploadBlob(

filePathHere,

CloudStorageAccount.DevelopmentStorageAccount,

"files");

// Download

Stream stream = _blobUtil.DownloadBlobAsStream(

CloudStorageAccount.DevelopmentStorageAccount,

blobUri.ToString()

);


Associated Example

On running the example, after opening and uploading an image file, you can see the following result. The first box shows the source image. The second box shows the uploaded image from Azure.

clip_image002

Pre-Requisites

Please ensure the Storage Emulator is running while testing the example

Reference

You can find more information on Block and Page blob using following link:

http://msdn.microsoft.com/en-us/library/windowsazure/ee691964.aspx

Summary

In this article we have seen the usage of Block Blob upload as chunks. The source code can be used to upload large files to Azure Blob. The associated example can be downloaded along with this article. The utility method was verified with 100MB file upload and download.

Posted in Azure | Tagged: , , , , , , , , , | 2 Comments »

Windows Azure – WCF in Worker Role

Posted by JP on November 29, 2011

In this article I am going to demonstrate the creation of WCF service in Worker Role and deployment to the cloud.

The attributes of WCF service on Worker role are:

  • Self Hosted
  • More Flexibility Attained
  • More Configurations Needed

Following are the steps involved.

Step 1: Create the WCF Service

Create a new Windows Azure project in Visual Studio 2010 and name it as WCFInWorkerRole as shown below

clip_image002

In the appearing dialog add one Worker Role project as shown below.

clip_image004

Add reference to the System.ServiceModel assembly.

clip_image006

Add the following 2 files

  • Interface named IMessengerService
  • Class named MessengerService

Replace the contents of above files with the following:

// IMessengerContract.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

namespace WorkerRole1

{

[ServiceContract]

public interface IMessengerService

{

[OperationContract]

string SendMessage(string name);

}

}

// MessengerService.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

namespace WorkerRole1

{

public class MessengerService : IMessengerService

{

public string SendMessage(string name)

{

return “Hello ” + name + “. How do you do?”;

}

}

}

Remove the app.config from the worker role project as we are going to do manual configuration of WCF service. Now the solution explorer looks like below:

clip_image008

In the case of web role, the context and port was automatically identified. But in the worker role, we need to update the properties manually. The host name will be different in the development and deployment servers.

Modify the ServiceDefinition.csdef file as below.

<?xml version=”1.0″ encoding=”utf-8″?>

<ServiceDefinition name=”WCFInWorkerRole” xmlns=”http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition”&gt;

<WorkerRole name=”WorkerRole1″ vmsize=”Small”>

<Imports>

<Import moduleName=”Diagnostics” />

</Imports>

<Endpoints>

<InputEndpoint name=”port” protocol=”tcp” port=”9001″ />

<InputEndpoint name=”mexport” protocol=”tcp” port=”8001″ />

</Endpoints>

</WorkerRole>

</ServiceDefinition>

The content defines the port and metadata port for our WCF service. Now we can modify the OnStart() method of the Worker role class as given below.

public override bool OnStart()

{

// Set the maximum number of concurrent connections

ServicePointManager.DefaultConnectionLimit = 12;

// Create the host

ServiceHost host = new ServiceHost(typeof(MessengerService));

// Read config parameters

string hostName = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[“port”].IPEndpoint.Address.ToString();

int port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[“port”].IPEndpoint.Port;

int mexport = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[“mexport”].IPEndpoint.Port;

// Create Metadata

ServiceMetadataBehavior metadatabehavior = new ServiceMetadataBehavior();

host.Description.Behaviors.Add(metadatabehavior);

Binding mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();

string mexendpointurl = string.Format(“net.tcp://{0}:{1}/MessengerServiceMetadata”, hostName, 8001);

host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, mexendpointurl, new Uri(mexendpointurl));

// Create end point

string endpointurl = string.Format(“net.tcp://{0}:{1}/MessengerService”, hostName, 9001);

host.AddServiceEndpoint(typeof(IMessengerService), new NetTcpBinding(SecurityMode.None), endpointurl, new Uri(endpointurl));

// Open the host

host.Open();

// Trace output

Trace.WriteLine(“WCF Listening At: ” + endpointurl);

Trace.WriteLine(“WCF MetaData Listening At: ” + mexendpointurl);

return base.OnStart();

}

The code performs the following:

  • Create Service Host
  • Read the Port number
  • Add the Metadata behaviour
  • Add the endpoints
  • Opens the Host

Note: The attached source code contains the working application.

Step 2: Test the application

Now we can test the application by executing it. If successfully executed we can see the trace from the Output window.

clip_image010

You can see two addresses from the above screen:

  • The actual service end point
  • The metadata end point

We can also see the trace from the load development machine. The Windows Azure Compute Emulator can be used for this purpose.

clip_image012

On invoking the Show Computer Emulator UI we can see the following window.

clip_image014

The above window contains the same trace output with the end point urls. You may try adding reference to the metadata end point using the metadata url. We are going to deploy the service to cloud and test it.

Step 3: Deploy to the cloud

Now our application is working fine and we can deploy it to the online cloud. For this right click on the project and click Package menu item.

clip_image016

In the appearing dialog box, choose the default options and click the Package button.

clip_image018

Now sign in to the Windows Azure portal and click on the New Hosted Service button from the top ribbon.

clip_image020

In the appearing dialog box enter the details as shown below.

clip_image022

Choose the option “Deploy to production environment”

Locate the package and configuration files from your application bin folder.

(Eg: ..\WCFInWorkerRole\bin\Debug\app.publish)

Please note that the URL prefix should be a unique name. If the URL prefix entered is already in use you need to change it.

After that click the Ok button of the dialog box. (You have to scroll down to see the button)

If any warning box appears, click Yes button to continue. Wait for a few minutes and your deployment will be ready in a few minutes as shown below.

clip_image024

Select the Deployment 2 row and from the properties window you can get the url of the worker role. Now we just need the host name. In this case wcfinworkerrole.cloudap.net

clip_image026

Step 3: Create the Client

Now we are ready to create the client application and test the deployed online cloud WCF service.

Create a new console application into the existing Azure project and name it as TestClient.

Use the add service reference option of the console application and in the appearing dialog enter the constructed service url as shown below.

Constructed Url: net.tcp://wcfinworkerrole.cloudapp.net:8001/MessengerServiceMetadata

Please note that we added the following:

  • Protocol as net.tcp
  • Host Name from previous step
  • Port number as 8001
  • Metadata Context Name

clip_image028

Click the Go button and after seeing the MessengerService item populated, Click the Ok button to continue.

Modify the main method in the Program.cs as following:

static void Main(string[] args)

{

ServiceReference1.MessengerServiceClient client = new ServiceReference1.MessengerServiceClient();

string result = client.SendMessage(“Kent”);

Console.WriteLine(string.Format(“Invoking WCF Service Result: {0}”, result));

Console.ReadKey(false);

}

Modify the configuration file with the url of the Messenger Service. Please note that the messenger service url is having different port number and context.

<client>

<endpoint

address=”net.tcp://wcfinworkerrole.cloudapp.net:9001/MessengerService

binding=”netTcpBinding”

bindingConfiguration=”NetTcpBinding_IMessengerService”

contract=”ServiceReference1.IMessengerService”

name=”NetTcpBinding_IMessengerService” />

</client>

Now set the console application as the start project and execute the application.

You can see the following results.

clip_image030

You can see the result Hello Kent. How do you do? from the WCF service.

This concludes our article on WCF service deployment as worker role and the testing.

Multiple End Point

I would like to add a note on the 2 end points we created for the WCF service.

net.tcp://wcfinworkerrole.cloudapp.net:8001/MessengerServiceMetaData

net.tcp://wcfinworkerrole.cloudapp.net:9001/MessengerService

You can see that there are 2 differences in the above urls:

  • Port
  • Context

Note: WCF with HTTP Port 80 endpoint configuration done as explained here.

Summary

In this article, we have seen how to host a WCF service using the Worker Role and deploy it to the cloud. This service is self hosted and experiments the service creation, hosting, metadata end point adding, deploying and testing with the client. The source code is attached and the application name in the url has to be changed according to your application name.

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

Windows Azure – WCF in Web Role

Posted by JP on November 29, 2011

In this article I would like to demonstrate the creation and deployment of WCF service in a Web Role.

The attributes of WCF service on Web role are:

  • IIS Hosted
  • IIS features like pooling and caching availability
  • Less Configurations Needed

Following are the steps involved.

Step 1: Create the WCF Service

Create a new Windows Azure project in Visual Studio 2010 and name it as WCFInWebRole as shown below

clip_image002

In the appearing dialog add one Web Role project as shown below.

clip_image004

Add a new WCF Service into the project. Name it as MessengerService.

clip_image006

Now the Solution Explore will look like below with the newly added contracts and service files.

clip_image008

Modify the DoWork() method in the interface IMessengerService as given below.

string SendMessage(string name);

Modify the DoWork() method in the interface IMessengerService as given below.

public string SendMessage(string name)

{

return “Hello ” + name;

}

Step 2: Test the application

Make the MessengerService.svc file as the start page as shown below.

clip_image010

Press F5 to execute the application and you can see the service opened in the browser as shown below.

clip_image012

Now are have tested the application and it is ready to be deployed to the cloud.

Step 3: Deploy to the cloud

Right click on the Web Role project and click package menu item as shown below.

clip_image014

In the appearing dialog select the default option and click the Package button.

clip_image016

Now sign in to the Windows Azure portal and click on the New Hosted Service button from the top ribbon.

clip_image018

In the appearing dialog box enter the details as shown below.

clip_image020

Choose the option “Deploy to production environment”

Locate the package and configuration files from your application bin folder.

(Eg: ..\WCFInWebRole\bin\Debug\app.publish)

Please note that the URL prefix should be a unique name. If the URL prefix entered is already in use you need to change it.

After that click the Ok button of the dialog box. (You have to scroll down to see the button)

If any warning box appears, click Yes button to continue. Wait for a few minutes and your deployment will be ready in a few minutes as shown below.

clip_image022

Select the Deployment 1 row and from the properties window you can get the url of the web role.

clip_image024

Click on the url and your application will get opened in the browser. Add the suffix MessengerService.svc to get the messenger service.

clip_image026

Step 3: Create the Client

Now we are ready to create the client application and test the deployed online cloud WCF service.

Create a new console application into the existing Azure project and name it as TestClient.

Use the add service reference option of the console application and in the appearing dialog enter the service url as shown below.

clip_image028

Click Ok button to continue.

Modify the main method in the Program.cs as following:

static void Main(string[] args)

{

ServiceReference1.MessengerServiceClient client = new ServiceReference1.MessengerServiceClient();

string result = client.SendMessage(“Ian”);

Console.WriteLine(string.Format(“Invoking WCF Service Result: {0}”, result));

Console.ReadKey(false);

}

Now set the console application as the start project and execute the application.

You can see the following results.

clip_image030

You can see the result Hello Ian from the WCF service.

This concludes our article on WCF service deployment as web role and the testing.

Summary

In this article we have seen how to deploy a WCF service to cloud platform. The WCF service inside the Web role will be hosted in IIS. The source code is attached and the application name in the url has to be changed according to your application name.

Posted in C# | Tagged: , , , | Leave a Comment »

Windows Azure – WCF Hosting Methods

Posted by JP on November 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 – Connecting to SQL Azure using Management Studio

Posted by JP on November 13, 2011

Another reusable tool over the SQL Azure is Management Studio. In this article we are going to explore the aspects regarding SQL Server Management Studio 2008.

clip_image002

Version

We can use the Management Studio for SQL Server 2008 R2. If you do not have this version installed, you can download an express edition which is free. (Please note that this is a CTP version)

Note: The Enterprise Manager associated with SQL Server 2000 and the Management Studio of SQL Server 2005 cannot be used with SQL Azure.

Download

You can download the SQL Azure supported version of Management Studio below:

32 bit

64 bit

Based on your Processor Architecture, download the appropriate version. The setup file should be around 160 MB in size.


Running the Setup

After running the setup you can view the following screen.

clip_image004

Use the highlighted option to proceed. (There will be a series of pre-requisites for the installation)

Run the Management Studio

After installation open the management studio from the start menu.

Connecting to SQL Azure

Open the Management Studio and in the appearing login dialog enter your SQL Azure credentials.

clip_image006

You will be taken to the Explorer view after the successful login. Now you can create new database, table, run SQL queries in the management studio. These activities are familiar with almost all developers and so not worth depicting. In the next article we will discuss another replacement for Management Studio.

Note: The OData (OpenData) feature of SQL Azure allows us to read the data over the browser, write LINQ queries on it etc.

Summary

In this article we explored connecting to online SQL Azure database. This advantage allows us to reuse our familiarity with SQL Server Management Studio.

Posted in C# | Tagged: , , | Leave a Comment »

Windows Azure – Adding Certificate in Portal

Posted by JP on November 13, 2011

Certificates are required to for authentication in a much secured way. In Windows Azure portal we can create certificates.

In this tutorial we are following the steps to create a certificate which will be used in the next article.

The activities involved are:

  • Create the certificate
  • Upload certificate to portal

Open the Visual Studio command prompt as administrator.

clip_image002

On the command prompt, enter the following command to create certificate named MyCertificate.cer.

makecert -sky exchange -r -n “CN=MyCertificate” -pe -a sha1 -len 2048 -ss My “MyCertificate.cer”

clip_image004

If the reply is Succeeded you are ready with the certificate. Note the path where the certificate is created.

Now we need to upload the certificate to Windows Azure Portal. For this sign in to the portal and choose the Management Certificates item as shown below.

clip_image006

In the appearing screen below, click on the Add Certificate button

clip_image008

A new dialog will be appearing.

clip_image010

Locate the certificate file (MyCertificate.cer) using the Browse button above and click Ok.

Now within a few minutes the certificate will be added to the account. See the status below.

clip_image012

If you can see the new certificate item the adding of certification succeeded.


Summary

In this article we have seen how to create a certificate and add to windows azure portal. The certificate will be used in the next article for MMC tool.

Posted in C# | Tagged: , , , | Leave a Comment »

Windows Azure – Create Queue in Storage Account

Posted by JP on November 6, 2011

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

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

  • Blob
  • Table
  • Queue

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

Concepts in Queue

Following are the key concepts in queue.

  • FIFO implementation
  • Messages are added to end of the Queue and processed from the front
  • Queues provides a good way of Front end and Back end decoupling

In the real world example the user can queue a job through the web role (front end) and the job can be processed by a worker role (back end). This gives an opportunity to decouple the web role and worker role.

clip_image002

Note: Blob are stored in container, Entity in table and Message in Queue

The steps involved in creating a queue 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_image004

Step 2: Modify the Default.aspx

Place a new label control on the aspx page and add the following code in the page load event.

protected void Page_Load(object sender, EventArgs e)

{

StorageCredentialsAccountAndKey accountAndKey = new StorageCredentialsAccountAndKey("account", "key");

CloudStorageAccount account = new CloudStorageAccount(accountAndKey, true);

CloudQueueClient client = account.CreateCloudQueueClient();

CloudQueue queue = client.GetQueueReference("workitems");

queue.CreateIfNotExist();

CloudQueueMessage message = new CloudQueueMessage("Test Work Item");

queue.AddMessage(message);

// Populate the messages

message = queue.GetMessage();

if (message != null)

Label1.Text = "Message in Queue: " + message.AsString;

}

Place your account name and key in the credentials. Ensure that the queue name is lower case (upper case will throw exception)

The above code will create a new message in the queue and after that it will retrieve the queue message and show in the page.


Important Classes

The important classes in the queue processing are stated below:

· CloudQueueClient

  • CloudQueue
  • CloudQueueMessage

The CloudQueueClient class takes care of getting the queue reference from the storage account. The CloudQueue class takes care of the holding the queue object. The CloudQueueMessage holds the actual message for the queue.

Summary

In this article we have seen how to put message into Queue and later retrieve it. The code attached contains the projects discussed above.

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

Create Table in Storage Account

Posted by JP 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.

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