Azure DataMarket– Writing Code to Consume DataMarket Data

 

  Introduction Windows Azure Marketplace DataMarket
 
This blog is based on a lab exercise in the Windows Azure Platform training Kit. The lab is called Introduction to Windows Azure Marketplace DataMarket. I ran through the lab to see if I could get it to work. And it does work. The basic first steps in the lab:
Step 1 -Signing Up Navigate to https://datamarket.azure.com/ and use your Windows Live ID to sign up.
Step 2 - Fill in Account Details Name, email address, etc. Agree to DataMarket privacy policies. Click the Continue button.
Step 3 -Explore your account keys The lab instructs you to go to My Account to get account keys. Your account key is used to access the data from client applications.
Step 4 - Browsing the data sources You can navigate the DataMarket to find the data that makes sense to you.

If you haven’t done so, download the free kit now:
Windows Azure Platform Training Kit Download

https://www.microsoft.com/downloads/en/details.aspx?FamilyID=413E88F8-5966-4A83-B309-53B7B77EDF78&displaylang=en


Sign up to Gender Info
The lab has you sign up for Gender Information from the United Nations database. Note that not all data sources are free. MyImage
Once you sign up, you can begin to explore the data: MyImage
Note the query that is setup for you. You can modify the query as needed:
Query for Italy Note the query now has been modified to include results for just Italy.

https://api.datamarket.azure.com/Data.ashx/UnitedNations/GenderInfo2007/Values? $filter=CountryName%20eq%20%27Italy%27&$top=100

  Consuming the Data from Visual Studio
  Some basic steps to consume data
Step 1 Start Visual Studio and open the starter project
Step 2 Add a service reference to the data
Step 3 Add using statements
Step 4 Add the Account Key to your code so you can access the data
Step 5 Create a LINQ query to get to the data
Step 6 Run the code and see the results displayed

At a high level, here are the changes we will need to make: pjhnnbo4 Here is the class we added:
Service Reference for UN Gender Data https://api.datamarket.azure.com/Data.ashx/UnitedNations/GenderInfo2007/
Service Reference Name UNData
Using Statements to add using System.Net; using ConsumingDataMarketData;
image 

Here are the results: image


Intellisense is available – notice that as soon as we hit the period (.) we get information about our data source, making the coding less error-prone.

MyImage

Conclusion

It is very easy to consume DataMarket data. It is in atom pub format. Also notice that we did not need to worry about putting the OData syntax. Just execute the LINQ query and the tooling takes care of the rest.