Windows Phone 7 DOL Data Sample
Overview
This sample will provide the steps to create a simple Windows Phone 7 application that can consume DOL Data. A windows Phone 7 SDK doesn't currently exist, however one will be provided in the future.
We will use the OData Client tool to generate a proxy class to access the API. Following these steps in order will allow your application to operate correctly.
Download this project |
Download project for Service Operation.
This solution was built using:
- Microsoft's Visual Studio 2010
- .Net Framework 4.0
- Windows Phone 7 SDK
- WCF OData Client Tool Version 5.0 is already included in this project, you can download it as well from here
- JSON.NET framework is already included in this project, you can download it as well from here
Download the Windows Phone 7 SDK
You will need a Windows Phone 7 SDK in order to run this sample. Download and install the Windows Phone 7 SDK from
here.

Create a New Project
For this sample we are going to create a new Windows Phone 7 application that will consume and list Occupation Employment Statistics data.

Select the default Windows Phone 7 application and confirm project details in the project setup page. This project is built using Windows Phone 7.0 runtime.

Add SDK to Project
All requests require account credentials to be submitted along with the request.
This SDK contains a few classes needed to process service requests.
These files need to be imported into your project.

Locate the Dataset Path
Each Dataset has a Dataset Location path that gives the URL that will be needed to create the proxy class to reach the Dataset on the API. For this sample please see the one circled on red.
For the DOL Service Operation sample please use http://api.dol.gov/V1/SummerJobs
Generate Proxy Class Code
The WCF OData Client Tool Version 5.0 is included in this project, and can be downloaded here.
Using the DataSvcUtil.exe tool, create a class file for the Dataset you intend to use.
For this sample Occupation Employment Statistics data path,http://api.dol.gov/V1/Statistics/OES2010,
is used to produce the Occupation proxy Class(Occupation.cs).
* It is important to note, use Version:2.0 and /DataServiceCollection options when using tool.
* It is important to note, proxy class generation is only required for standard DOP API dataset, for DOL service operation ,steps are defined later in this document.

Include Occupation Employment Statistics Proxy Class in Project
The Occupation Employment Statistics data can be accessed using the OES2010Entities class which is in Occupation.cs.
This file needs to be included into your solution.

Define the User Interface
For standard DOL API datasets:
Add a simple ListBox to the MainPage.xaml file. This markup should be placed in the Grid named ContentPanel.

For standard DOL Service Operation:
Add a simple ListBox to the MainPage.xaml file. This markup should be placed in the Grid named ContentPanel.

Implementing the DOL Data Request
Include Using statements to reference the appropriate classes. These statements will allow your project to access OES2010Entities classes and OData Classes. This project will also need to include the gov.dol.doldata.util namespace to reference the SDK.
Create an event handler to execute when the page has been loaded.

Sample code for standard DOL API datasets:
Using the OES2010Entities Class assign the Occupation Employment Statistics Dataset path to reflect http://api.dol.gov/V1/Statistics/OES2010/ url.
The LoadAsync method takes two parameters. The API query and a callback method that will be executed when the results have been returned.
Currently the Windows Phone 7 environment doesn't support Linq queries to make API calls.

Sample code for DOL Service operation:
Using class DOLDataUtil which is part of SDK , we are going to invoke DOL service operation.The LoadServiceRequest method takes three parameters. The API Dataset Location path ,API query and a callback method that will be executed when the results have been returned.
Each String typed parameter must be surrounded in quotes in order to work correctly. These quotes are then Url encoded and passed to the Service Operation.
Currently the Windows Phone 7 environment doesn't support Linq queries to make API calls.

We need to implement the callback method that will be fired when the API has responded to our request. We will bind the results to our UI.
Sample code for standard DOL API datasets:

Sample code for standard DOL Service operation:
We will get json result from DOL API for service operation , which needs to cleanup and then should be parse using Json.NET Library. Json.NET high-performance JSON framework for .NET and it also supports .NET 2, .NET 3.5, .NET 4, Silverlight, Windows Phone and Windows 8 Metro.
Create Class Job with one property called "Titile" of string data type. We will create the list of Job class and set as datasource to Listbox.List of jobs will be filled from json result.


Configure Security
Once the SDK has been added to the project, we will need to modify both the ApiKey and the SharedSecret members of this class to access DOL Data.
Edit the DOLDataUtil class within the DOLDataUtil.cs file.
- The ApiKey corresponds to the Token identifier in your token list.
- The SharedSecret created during setup is the same value that is used in the DOLDataUtil class.
- *Note: DOLDataUtil Class may be inaccessable due to its current access specifier. Precede with public keyword to resolve this problem.
Run the Application
Run the application and you should see a list of occupations in the grid.
Sample code for standard DOL API datasets:
Sample code for DOL Service operation: