Quantcast
Channel: ICT Blog » Microsoft
Viewing all articles
Browse latest Browse all 39

LightSwitch application consumes OData service from the Windows Azure Marketplace

$
0
0

Nederlandse versie

To get some hands-on experience with the Windows Azure Marketplace I decided to use a free data source and to build a LightSwitch application on top of it. Having some LightSwitch experience I knew that OData sources could be used as a LightSwitch data source and that LightSwitch makes it possible to do some real rapid application development.

In this example I use Visual Studio 2012 Premium, LightSwitch 2.0 en data from the Rijksdienst voor het Wegverkeer (RDW). This is the Dutch organization for Vehicle Registration. The RDW offers free vehicle data as test for a period of 1 year.

Windows Azure Marketplace
Using a Microsoft Live ID you can register for the Windows Azure Marketplace. After registration, data from the Windows Azure Marketplace can be used or bought. When writing this blog post 136 data sources were available. Using the RDW data is free and the only limitation is the number of transactions each month (50.000).

LightSwitch project
In Visual Studio 2012 I chose a new LightSwitch C# project.

Select a data source
First step is to chose a data source. A LightSwitch application is data-centric. One can chose form using a database or using an external data source. I chose the latter and then an OData service.

Then the OData Service must be defined.

The endpoint for the OData Service is the URL supplied by the RDW in the Windows Azure Marketplace. When creating an account for the Windows Azure Marketplace a unique Customer-Id  and a Primary Account key were provided. These are the User name en Password for the OData Service. In this case a read-only connection is all I need.

When endpoint and credentials have been entered, the entities of the OData Service can be retrieved and are shown.

In this case the RDW uses a single table with technical vehicle data. Now the source data wizard has completed, the LightSwitch project contains one table.

The goal of this application is to request technical data for a single vehicle by using the unique license plate as parameter. This is no out-of-the-box LightSwitch scenario. Usually, LightSwitch applications have a screen that is filled with data when the application starts. In this case I don´t want to get the data right away; I want to let the user specify a license plate number first. To get my application to act like this I first define a query to be able to search the data based on license plate number.

Right click on the table and select New Query to create a new query.

In this query I specify that the Kenteken (license plate number) of the KENT_VRTG_O_DAT table must match a parameter that I also call Kenteken. Luckily, LightSwitch uses different colors so I am still able to see the difference between the data source field and the parameter…;-)

The screen
Next we create a screen and we select the query as the source for this screen. I use a List and Details Screen as my starting point.

Hit OK to create the screen. By default, this screen contains a list with data source entries and when a list  entry is selected, details about this entry are displayed using data fields. In this case that is not the intention because I only want the data for a single vehicle. Therefore, I remove the list from the screen but I keep the details part. Also I don´t want the application to get data from the data source when the application starts. To prevent this from happening some query properties must be adjusted:

I have to:

  • deselect Auto Execute Query to prevent the query from executing upon startup.
  • deselect Support paging en Support sorting because I don’t have a list.
  • deselect Support search because I only want to search on license plate number and not on any other data source field.

Because I used a query as data source for the screen LightSwitch created an edit box (Kenteken) on the screen (1):

However, just an edit box for the Kenteken parameter is not enough. An additional button is needed to trigger the execution of the query. So I add a Zoeken (Search) button right behind the edit box (2). This can be achieved by right clicking on the Kenteken edit box field and then selecting the Add Button option. Then the method to be invoked when the button is pressed can be defined:

To get this button to perform an action, the only line of code for this complete application must be written. Right click on the Zoeken button and select Edit Execute Code to open the related C# file:

public partial class KentekenQueryListDetail
{
   partial void Execute_Search_Execute()
   {
      // Write your code here.</span>
      this.KentekenQuery.Load();
   }
}

This code executes the query. The entered license plate number in the edit box is supplied as parameter to the query. Results are technical data of the vehicle with the provided license plate number.

Ready
And now our application ins ready. Hit F5 to build and debug the application. The screen appears. After entering a Dutch(!!!!) license plate number (without the dashes) and pressing the Zoek button, the data is retrieved from the RDW and displayed on the screen. Unfortunately for my English oriented visitors, the data fields are all in Dutch.

Next time
After playing around some more with this application there are plenty of transactions left to experiment some more.

Although the application is up and running now it is running on my laptop. In my next post I will deploy this application into a Windows Azure Web Site. A task that takes minutes…


Viewing all articles
Browse latest Browse all 39

Latest Images

Trending Articles





Latest Images