programming4us
programming4us
DATABASE

SQL Azure : Building Two OData Consumer Applications (part 1) - Simple Demo App

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
1/21/2011 2:43:36 PM
The rest of this article focuses on building two applications that consume the OData service that you just enabled on your SQL Azure database. The first one is very simple, to whet your appetite and show you the basics. The second is the cool one. (But don't skip the first one!)

7.5.1. Simple Demo App

For this first example, create a Windows Forms Application project. The name of the project and language don't matter. When your project is created, follow these steps:

  1. Drop a list box and a button on the form.

  2. In Solution Explorer, right-click the References node, and select Add Service Reference from the context menu.

  3. When the Add Service Reference dialog appears, you need the URI you copied from this article. Paste it into the Address field, and click the Go button. After several seconds the available services and associated endpoints appear in the Services section of the form, as shown in Figure 1.

    Figure 1. Adding the OData service reference
  4. Leave the Namespace name as is, and click OK. A new Service Reference node appears in Solution Explorer, which lists the service you just added.

  5. In the code behind the form, add the following using statements:

    using System.Data.Services;
    using System.Data.Services.Client;

  6. In the declaration section, add the following two lines of code. The first line declares your context variable, which references the newly added service; the second line defines the URI that accesses the OData service:

    private ServiceReference1.TechBio context;
    private const string svcUri = "https://OData.sqlazurelabs.com/OData.svc/v0.1/servername/TechBio";

  7. In the button's click event, add the following code:

    context = new ServiceReference1.TechBio(new Uri(svcUri));

    var userQuery = from u in context.Users
    select u;

    foreach (var u in userQuery)
    {
    listBox1.Items.Add(u.Name);
    }

  8. Run the application. When the form displays, click the button. After a few seconds, the list box populates with usernames, as shown in Figure 2.

    Figure 2. Form displaying data via the OData service

Very simple, but a good foundation to build on. This example gives you an idea of how you can consume on OData service via a .NET application. But you're probably tired of waiting, so let's move on to the really cool example: the Windows Phone application.

Other  
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
REVIEW
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
programming4us
 
 
programming4us