Introduction to Windows Azure Marketplace...

download Introduction to Windows Azure Marketplace DataMarketaz12722.vo.msecnd.net/.../labs/introtodatamarket1-0/Lab…  · Web viewIntroduction to Windows Azure Marketplace DataMarket. ...

If you can't read please download the document

Transcript of Introduction to Windows Azure Marketplace...

Introduction to Windows Azure Marketplace DataMarket

Hands-On Lab

Introduction to Windows Azure Marketplace DataMarket

Lab version:1.0.0

Last updated:7/8/2011

Contents

Overview3

Exercise 1: Exploring the Microsoft Azure Marketplace DataMarket portal and Service Explorer5

Task 1 Accessing and Signing Up to the Microsoft Azure Marketplace DataMarket Portal5

Task 2 Exploring Your Account Keys8

Task 3 Exploring the Datasets in the DataMarket and Subscribing to a Dataset9

Task 4 Using Service Explorer to Preview a Dataset12

Exercise 2: Consuming DataMarket Data and Services via Managed Code14

Task 1 Adding a Service Reference14

Task 2 Consuming Data with Managed Code16

Exercise 3: Consuming DataMarket Data via PowerPivot20

Task 1 Importing Data From a DataMarket Dataset Into PowerPivot21

Task 2 Importing Data From an External Data Source Into PowerPivot26

Task 3 Creating a Relationship in PowerPivot27

Task 4 Creating a Simple Pivot Table With Your Data28

Summary33

Overview

In this lab, we will introduce Microsoft Azure Maketplace DataMarket. DataMarket is Microsofts Information Service offering which allows developers and information workers to find, acquire and consume published datasets and web services. Users subscribe to datasets and web services of interest and can integrate the information into their own applications via a standardized data services. Data can also be analyzed online using the DataMarket Service Explorer or externally using the PowerPivot Add-In for Excel.

Objectives

In this hands-on lab, you will learn how to:

Explore the Microsoft Azure Marketplace DataMarket portal and Service Explorer

Query a Microsoft Azure Marketplace DataMarket dataset using a URL

Access and consume a Microsoft Azure Marketplace DataMarket dataset and Service via Managed Code

Use the PowerPivot Add-In for Excel to consume and analyze data from Microsoft Azure Marketplace DataMarket datasets

System Requeriments

You must have the following items to complete this lab:

Microsoft Visual Studio 2010

Microsoft .NET Framework 4.0

Microsoft Office Excel 2010

PowerPivot

Setup

In order to execute this hands-on lab exercises you need to setup this lab.

Open a Windows Explorer window and browse to the labs root folder.

Double-click the Setup.cmd file in this folder to launch the setup process that will configure your environment and install the Visual Studio code snippets for this lab.

If the User Account Control dialog is shown, confirm the action to proceed.

Using the Code Snippets

0. Throughout the lab document, you will be instructed to insert code blocks. For your convenience, most of that code is provided as Visual Studio Code Snippets, which you can use from within Visual Studio 2010 to avoid having to add it manually.

If you are not familiar with the Visual Studio Code Snippets, and want to learn how to use them, you can refer to the Setup.docx document in the Assets folder of the training kit, which contains a section describing how to use them.

Exercises

This hands-on lab includes the following exercises:

Exploring the Microsoft Azure Marketplace DataMarket portal and Service Explorer

Querying Microsoft Azure Marketplace DataMarket Datasets via URLs

Consuming Microsoft Azure Marketplace DataMarket Data and Services via Managed Code

Consuming Microsoft Azure Marketplace DataMarket Data via PowerPivot

Estimated time to complete this lab: 60 minutes.

Note: When you first start Visual Studio, you must select one of the predefined settings collections. Every predefined collection is designed to match a particular development style and determines window layouts, editor behavior, IntelliSense code snippets, and dialog box options. The procedures in this lab describe the actions necessary to accomplish a given task in Visual Studio when using the General Development Settings collection. If you choose a different settings collection for your development environment, there may be differences in these procedures that you need to take into account.

Exercise 1: Exploring the Microsoft Azure Marketplace DataMarket portal and Service Explorer

In this exercise, we will sign up to the Microsoft Azure Marketplace DataMarket portal and use the Service Explorer to explore your service details and the DataMarket datasets.

Task 1 Accessing and Signing Up to the Microsoft Azure Marketplace DataMarket Portal

In this task you will access the Microsoft Azure Marketplace DataMarket portal and sign up:

Navigate to https://datamarket.azure.com/

If you have a Windows Live ID, use it to sign in. If you do not have a Windows Live ID, create one.

Once you have signed in, take some time to review the portal.

Figure 1

Microsoft Azure Marketplace DataMarket portal

Click Register link.

Figure 2

Clicking Register

Enter the requested information in Account Details, review the privacy statement, and select the checkbox to agree with DataMarket privacy policies. Click the Continue button.

Figure 3

Registering for DataMarket

Review the User Agreement, and accept it selecting the I accept the Terms of Use checkbox. Click Register button to finish registration.

Figure 4

Accepting User Agreement

Once registered you see the My Data page. If not automatically redirected click My Data button on ribbon.

Figure 5

My Data Page

Task 2 Exploring Your Account Keys

In this task, you will explore your account keys and create a new account key.

0. From the DataMarket Portal Home Page, click the My Account link. Alternatively, you can click on My Data tab.

Figure 6

Clicking My Account

0. Click Account Keys on left pane. To create a new account key, click the Add account key link.

Figure 7

Creating a new account key

The screen for adding an account key will display. Enter a description for the account key and click the Create button.

Figure 8

Adding a new Account Key

You will now see your new account key in the list of available keys.

Figure 9

Your new account key

Task 3 Exploring the Datasets in the DataMarket and Subscribing to a Dataset

In this task, you will explore the DataMarket. The DataMarket allows users to browse and subscribe to available datasets.

0. Click Browse tab.

Figure 10

Clicking Browse

Note: For each dataset, the DataMarket shows the data provider, a description of the datasets content, the type of the content, and provides a link that will allow you to subscribe to the dataset.

0. Using Search the MarketPlace, locate the UN DATA dataset called Gender Info 2007 United Nations Statistics Division. Use the key word Gender.

Figure 11

Searching Dataset

Click on the dataset and review the information. Click on Sign Up button to subscribe to the dataset.

Figure 12

Reviewing dataset information

Review and accept Dataset Terms. Click Sign Up button.

Figure 13

Signing Up Dataset Subscription

0. Review the Receipt.

Figure 14

Your DataMarket Subscription Receipt

Task 4 Using Service Explorer to Preview a Dataset

In this task, you will use the Service Explorer to preview a dataset to which you have subscribed.

0. From the DataMarket Portal, click the My Data tab; you will see a list of your subscribed datasets.

0. Locate the Free subscription for Gender Info 2007 Dataset and click the title to open subscription.

0. Click Explore This Dataset link.

Figure 15

Exploring the dataset

0. The dataset will open in the Service Explorer.

Figure 16

Service Explorer

Note: You can use the Service Explorer to query the dataset, invoke the dataset as an Atom feed, or analyze the dataset using the PowerPivot add-in for Excel 2010.

0. Modify or set some of the Optional parameters and click the Run Query button. This will display a preview of the dataset based on the criteria you set.

Figure 17

Previewing your Dataset

0. By default, the preview will display in Table format, however you can click Atom Pub link to preview the dataset in Atom Pub format.

Figure 18

Preview Formats

Exercise 2: Consuming DataMarket Data and Services via Managed Code

In this exercise, you will add the service reference to consume DataMarket data. You will create a class to expose the consumed DataMarket data.

Task 1 Adding a Service Reference

In this task, we will add the service reference to consume DataMarket data.

0. Log on to the Windows Azure Marketplace DataMarket portal.

0. From the DataMarket Portal, click the My Data tab; you will see a list of your subscribed datasets.

0. Locate the subscription for Gender Info 2007 Dataset and click the title to open subscription.

0. Click on Explore This Dataset link to open dataset details.

Figure 19

Exploring the Dataset

0. From the dataset explorer page, copy the Service root URL link.

Figure 20

Copying Service root URL

0. Open Microsoft Visual Studio 2010.

0. Open solution called begin.sln located in the Source folder Ex02-ConsumingDataMarketDataAndServicesViaManagedCode\begin\CS.

0. Right click on the ConsumingDataMarketData project and select Add service reference.

0. Paste the URL you copied into the Address textbox. Click on the Go button. Once the service is discovered, add UNData as Namespace.

Figure 21

Adding Service Reference

Task 2 Consuming Data with Managed Code

In this task, you will create a simple class that wraps the dataset queries.

Add in ConsumingDataMarketData project, a class called UNGenderData.

Figure 22

Adding UNGenderData

Add System.Net and ConsumingDataMarketData.UNData to the using list.

(Code Snippet Introduction to DataMarket Ex2 Adding Using CS)

C#

using System.Net;

using ConsumingDataMarketData.UNData;

Add the public access modifier to the class UNGenderData.

Add the properties serviceUri and context to your class.

(Code Snippet Introduction to DataMarket Ex2 Adding Properties CS)

C#

private Uri serviceUri;

private UnitedNationsGenderInfo2007Container context;

Create the class constructor with the following code inside.

(Code Snippet Introduction to DataMarket Ex2 Create Constructor CS)

C#

public UNGenderData()

{

serviceUri = new Uri("{replace-with-dataset-url}");

context = new UnitedNationsGenderInfo2007Container(serviceUri);

context.Credentials = new NetworkCredential("{replace-with-your-user-id}",

"{replace-with-your-key}");

}

Replace the placeholder in the code with the actual data. To do this, navigate back to the DataMarket portal.

Click on the My Data tab.

On the left side under My Account, click on Account Keys link.

Replace {replace-with-your-user-id} placeholder with the account description you created on Exercise 1.

Replace {replace-with-your-key} placeholder with the account key.

Figure 23

Getting Account Key details

On the left side under My Account, click on Datasets link.

Click on Gender Info title to view details of the dataset.

Click on the Explore this Dataset link.

Copy Service root URL link.

Figure 24

Getting Account Key details

Replace {replace-with-dataset-url} placeholder with the url you copied.

Add the following code to the class.

(Code Snippet Introduction to DataMarket Ex2 GetValues Method CS)

C#

public IList GetValues()

{

IEnumerable query;

query = from value in context.Values

where value.CountryName == "Argentina"

select value;

try

{

return query.ToList();

}

catch (Exception ex)

{

Console.WriteLine("Error: {0}", ex.Message);

return null;

}

}

Note: The method GetValues() queries the context provided by the DataMarket service. You can add other methods that query using other parameters. To do this you can review the different optional parameters on the dataset service explorer page.

Copy the following code on the Program class Main method.

(Code Snippet Introduction to DataMarket Ex2 Main Method CS)

C#

UNGenderData data = new UNGenderData();

foreach (var value in data.GetValues())

{

Console.WriteLine(string.Format("Country {0} year {1} {2} value {3}", value.CountryName, value.Year, value.SubGroupName, value.Value));

}

Console.ReadKey();

Run the application by pressing the F5 key. A Console window will open and a tabular view of the data returned by our query will be displayed. Press the Enter key to close the Console window.

Figure 25

Console running

Exercise 3: Consuming DataMarket Data via PowerPivot

In this exercise, you will use the Excel Add-In PowerPivot to consume and analyze data from DataMarket datasets.

Task 1 Importing Data From a DataMarket Dataset Into PowerPivot

In this task, you will import data from a DataMarket dataset into PowerPivot.

Navigate to https://datamarket.azure.com/.

Locate the UN data dataset UNESCO UIS Data.

Click on title to view detail information.

Click Sign Up button to subscribe.

Figure 26

UNESCO UIS Data Dataset

Agree and confirm subscription. To do this, check the checkbox and click on Sign Up button.

Click on the Explore This Dataset link.

Select Values on Query dropdown box. Complete with optional parameters. To narrow the query you can write 2000 on the TimePeriod textbox. Select PowerPivot and click Open button.

Figure 27

UNESCO UIS Data Dataset service explorer

Click on the Open button.

Figure 28

Opening the atom feed

If prompted, select and click Ok button, when prompted by PowerPivot.

Figure 29

Selecting the workbook

Microsoft Excel will launch and the PowerPivot Table Import Wizard dialog will display. On the Table Import Wizard, complete with a Friendly connection name and copy your account key into the Account Key textbox. To do this, see exercise 2 task 2. Optionally, check Save my account key. Click Next button.

Figure 30

Excel Table Import Wizard

Click Finish button to start importing information.

Figure 31

Importing dataset data

The wizard will import data from the dataset, when finished click on the Close button. The imported data will be displayed in PowerPivot. Keep the PowerPivot window open to do the next tasks.

Note: The import operation may take several minutes to complete.

Figure 32

Dataset imported into PowerPivot

Task 2 Importing Data From an External Data Source Into PowerPivot

In this task, you will import data from an existing Excel spreadsheet into PowerPivot.

0. From the PowerPivot window, click the From Other Sources toolbar item.

Figure 33

From Other Sources option on PowerPivot toolbar

0. On the Table Import Wizard, scroll down and select Excel File and click Next. Click the Browse button. Browse to Ex03-ConsumingDataMarketDataViaPowerPivot\ in the Source folder of this lab, select the RegionOrArea.xlsx file, and select the Use first row as column headers option. Click Next to select the tables, which will be imported. Make sure that the RegionOrArea$ source table is checked. Click Finish to import the file into PowerPivot. Finally click Close.

Figure 34

The Excel spreadsheet imported into PowerPivot

Task 3 Creating a Relationship in PowerPivot

In this task, you will create a relationship between the two sets of data we have imported into PowerPivot.

From the PowerPivot toolbar, click the Design tab.

Figure 35

Design tab on the PowerPivot toolbar

From the PowerPivot Design toolbar, click the Create Relationship button.

Figure 36

Create Relationship button on the PowerPivot Design toolbar

Set the following criteria on the Create Relationship dialog box:

Table: RegionOrArea

Column: RegionOrAreaCode

Related Lookup Table: UNESCO UIS Data.

Related Lookup Column: ReferenceAreaCode

Figure 37

Create Relationship dialog window

Click the Create button. This will create a relationship between the two PowerPivot tables.

Task 4 Creating a Simple Pivot Table With Your Data

In this task, you will use PowerPivot to create a simple Pivot Table using the data imported in the previous tasks.

Click the Home tab on the PowerPivot toolbar.

Figure 38

Home tab on PowerPivot toolbar

Click the PivotTable button on the PowerPivot toolbar, choose the PivotTable option.

Figure 39

PivotTable button on the PowerPivot toolbar

On the Create PivotTable dialog box, choose the Existing Worksheet radio button and click the OK button, an empty Pivot Table will be displayed.

Figure 40

The empty Pivot Table

Set up the initial Pivot Table rows and columns as follows:

Drag the RegionOrArea field to the Row Labels list.

Drag the Sex field to the Row Labels list.

Drag the TimePeriod field to the Column Labels list.

Figure 41

Initial Pivot Table

Click the checkbox next to the ObservationValue field, this will populate the Pivot Table.

Figure 42

Populated Pivot Table

Right-click the Continent field and choose the Add to Slicers Vertical option. This will add a vertical slicing option to the Pivot Table.

Figure 43

Pivot Table with Vertical Slicer added

You can now slice your data based on the Continent that the data applies.

Summary

In this lab, we explored Microsoft Azure Marketplace DataMarket and how to subscribe, access and analyze the published datasets.