Windows Azure Marketplace Introductory teaching-datamarket experience

Source: Internet
Author: User
Keywords nbsp; Step
Tags .url application blog button class click code console

Windows®azure Marketplace (formerly known as "Dallas", this blog has also written an introductory teaching "preliminary study Dallas") DataMarket is an information market that simplifies publishing and the steps to use various types of data. DataMarket facilitates developers and information workers to discover, purchase, and manage ordered premium data.

The exposure format for data within DataMarket is OData and provides 2 patterns for data queries:

Flexible query: Allows users to add optional name value pairs of parameters to query data, such as (Columnname=foo). Fixed query: Users can query data only through the predefined operations of the content provider.

This article will briefly describe how to build a flexible query using Windows Azure Marketplace.

preparatory work: 1. A valid Windows Live ID account, if not, please register through the Windows Live Home page. 2. An effective DataMarket account. If not, visit Windows Azure Marketplace DataMarket and log in with your Live ID. After accepting a number of terms of use, you will have a DataMarket account that is bound to the Live ID. 3. Get your account keys on the Account Keys page, which is your voucher for using the service. 4. Visit the DataMarket Data Source list page, list the data sources in all DataMarket, select the data source of interest, click, enter the detail page of the data source. On the right side of the page, click the Sign Up button to order the data source (typically a free data source). After accepting a number of terms of use, we have finished ordering the data source. 5. We order 2006-2008 Crime in the United States service for follow-up project demonstrations.

Code: Step 1: Create a new project in Visual Studio to run Visual Studio 1 with administrator privileges. Run visual Studio with administrator privileges to create a new project 1. Create a new Visual C # console application. 2. Target Framework selection for the project (target framework) is. NET Framework 4. 3. Name the project uscrime2006and2007. 4. Click OK button. Step 2: Add a service reference to the project to get the root URL1 of the service. Visit the Windows Azure Marketplace datamarket home page and log in as a live ID. 2. Click My Data tab. 3. Find 2006-2008 Crime in the United States Data Service. 4. Click the Use link on the right side of the list of services. 5. Drag the page to the middle of the page and click on the Details tab.

6. Locate the root URL of the service.

adds a service reference of 1 to the project. Right-click the item in step 1 and select Add Service Reference .... 2. Enter the URL of the step into the Address bar of the dialog box. Click the Go button. 3. Set the namespace of the service to Datagovcrimes. 4. Click OK button. Add Service Reference 1 in code. Open the Program.cs file for the project. 2. Add the following reference statement in the file: using Uscrime2006and2007.datagovcrimes;

Step 3: Use the data in managed code to create a secondary class 1. Create a public class named Crimedata. 2. Add 2 private variables to the class: a root URL that represents the service. A service container that stores service credentials in the context of a service.  class crimedata{    Private Uri serviceuri;    private Datagovcrimescontainer Context;}  3. Create a constructor for Crimedata. Constructors initialize private variables and user credentials. Class crimedata{    private Uri serviceuri;    private Datagovcrimescontainer context;     //constructor for the Crimedata class    public crimedata ()        {        Serviceuri = new Uri (root_url);         context = new Datagovcrimescontainer (Serviceuri);        Context. Credentials = new NetworkCredential (user_id,                                                      SECURE_ACCOUNT_ID);    }} root_url  is the root URL of the service mentioned above. user_id  is your Live ID account name.


secure_account_key  your account Keys in DataMarket (refer to the preliminary work section). 4. Create a common method that returns a generic list of generic type Citycrime. Class crimedata{    private Uri serviceuri;    private Datagovcrimescontainer context;     //constructor for the Crimedata class    public crimedata ()     {        Serviceuri = new Uri (root_url);         context = new Datagovcrimescontainer (Serviceuri);        context. Credentials = new NetworkCredential (user_id,                                                       secure_account_id);   }     ReturnsThe list of crime data    public ilist<citycrime> getcrimedata ()     {         ienumerable<citycrime> query = context. Citycrime.where (Crime => crime. City = = "Newport"). By-crime => crime. Year);         try        {             return query. ToList ();       }        catch (Exception Ex)         {             Console.WriteLine ("Error: {0}", ex.) Message);            return null;        }   }}  

The query can be any valid DataMarket LINQ query that can include an optional where (where) or a by-order method.

5. Use the Crimedata class in the main () function, and the Getcrimedata () method to work with the data and display the results returned by the function.

 static void Main (string] args) {    ilist<citycrime> crimelist; //Citycrime is the Entity type returned by the service    crimedata crimedata = new Crimedata ();              crimelist = Crimedata.getcrimedata ();     if ( Crimelist!= null)     {        Console.WriteLine ("{0,4} {1,-12} {2 , -15} {3,10} {4,13} ', Year ',                                                                   "City",                                                                   "State",                                                                    " Population ",                                                                   "Violent Crime");                     foreach (citycrime C in crimelist)              Console.WriteLine ({0,4} {1,-12} {2,-15} {3,10} {4,13} ", C.year,                                                                         c.city                                                                          c.state                                                                          c.Population,                                                                      &nbSp;  c.violentcrime);   }     console.write ("Tap any key to exit.");     Console.readkey ();

6. Runs the program, and displays the results of the operation return in the console.

Summary:

We see in the code convenient for the use of the data source is very simple, developers can combine the actual application requirements, easily integrate the application with these real-time data sources, build a rich content of the application.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.