RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Running In the Field: How to Make Your Handheld Your Best Friend : Page 2

Enterprises take note: as handheld devices become both more capable and more user-friendly, they're also becoming "must-have" equipment for people who work away from the office, replacing their heavy laptops with smaller and lighter but still fully-functional equipment.

A Travelogue Application
As an example of creating a mobile connected application, the rest of this article describes the construction of a simple travelogue program. The program could serve as a personal application, but it's architected so it could also be the basis of a more complex business application.

Here are the goals for the application:

  • Users should be able to create, save, and browse "travel records." The meaning of a travel record can vary. For a tourist, it might be simply a place to remember; for an insurance or police investigator, it might be an accident scene; for a salesperson, it might be information about a customer, and so on. For demonstration purposes, each record contains only a title, a description, a date and time, a location, and a picture.
  • Users should be able to take a photo, using the handheld device, and associate that with a record.
  • Users should be able to capture the record location using the device's GPS capabilities. Each record will contain the exact position when the record was created. The position data can be used for later analysis on the server side.
  • The application should be able to send all collected data to a central server. The server stores records in a database, and potentiallly makes them accessible to all users of the application.
  • The application should be able to retrieve and edit existing records. Users should be able to retrieve and browse or update records stored previously.
The sample application will be a true smart client application, not just a web application that the mobile device access with a browser.

Author's Note: Binding GPS data to other collected data is an interesting operation that opens the door to creating geographically enabled business applications. A full discussion of managing geographic data, or associating that data with maps is out of the scope of this article, however you can find useful information in my earlier DevX articles, "Give Your Applications Mapping Capabilities" parts 1, 2, and 3.

Figure 1. The Sample Application's Main Screen: When users launch the sample application, they have the choice of creating new records or browsing existing records.
To follow along for development purposes, you need only Visual Studio 2008 and VB.NET, nothing else (VS includes a full emulator). However, if you want to test the functionality by loading the application onto a real device, you'll also need a Windows Mobile 5 or 6 device, with an internal or external GPS receiver, and photo capability. The Windows Mobile 6 SDK includes an emulator that can provide GPS functionality, so you can also download that as a testing platform. I strongly suggest you download and install the Windows Mobile 6 SDK, because you'll find a working example showing how to take a photo programmatically from .NET CF.

Application Structure
The application consists of a main form (see Figure 1) where users select an operation to perform, an entry form that collects user-entered data for new records, and a form for searching and displaying existing records.

A simple web service architecture serves to connect the mobile software with the central server application. It's worth mentioning that you could create this using many different technologies—including the new .NET 3.x Windows Communication Foundation (WCF)—but this example uses a simpler ASMX web service, a technology that's also available to VS 2005 users.

The data collection form collects user-entered data for all the required fields and makes the call to the remote web service to submit the collected data.

Author's Note: Creating the server side application is out of the scope of this article, which concentrates on creating the client. However, the downloadable sample application provides a simple dummy server-side component so you can see how a "real" central application would work with the mobile application.

Calling a web service from a .NET client application is quite trivial, as you'll see later; you just need to add a web reference in Visual Studio by selecting the "Add Web Reference..." item from the Project menu. You'll need to provide the current URL (obviously this URL can change later, for example when you go in production environment) of a working web service. Visual Studio decodes the web service's manifest and creates a lot of code for you. After successfully adding a web reference, you can call the methods exposed by the web service just as you would any local method. Behind the scenes, Visual Studio handles all the required operations to create the "real" interaction with the web service.

The Web Service
To supply the mobile application with a connection to the central server, you need a simple web service. The web service example used here exposes a Travelogue object and two methods. Remember, a Travelogue is a record that contains a title, a description, a date and time, a location, and a picture. The first method, LoadData, accepts a new object to save, assigns it a unique ID, and saves it to a back-end database (this is the dummy function, because there's no central application for it to connect to). Finally, LoadData returns the assigned ID to the caller.

The second method, GetTravelogues, takes a string used as a filter on the Title property, and returns a list of Travelogues according to filter. To simulate the name search, the dummy implementation returns a fixed list of Travelogue objects from a private function (GetDummyList), and filters that. So you will never see the objects you saved, because the list is immutable for this demonstration.

Author's Note: I used the new Language Integrated Query (LINQ) features to create a very quick and simple filter and retrieve function. This code works only on .NET 3.5, but LINQ is a very powerful feature. Creating the same functionality without LINQ requires both more work and results in less-intuitive code.

Here's some stub code for the two web methods:
   <WebMethod()> _
   Public Function LoadData( _
      ByVal newItem As Travelogue) As Guid
      ' -- assign a new guid
      newItem.ID = Guid.NewGuid
      ' TODO: saves data
      ' -- returns assigned guid
      Return newItem.ID
   End Function
   <WebMethod()> _
   Public Function GetTravelogues( _
      ByVal filterName As String) _ 
      As List(Of Travelogue)
      ' -- retrieves a filter output list from the dummy db
      Dim out = From t As Travelogue In GetDummyList() _
         Where t.Title.Contains(filterName) _
         Select t
      Return out.ToList
   End Function

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date