PocketPCs have become widely used pocket companions, especially for people on the move.
They are extremely versatile and if you are using the device for basic functionality like mail, contacts and reminders can almost replace a notebook.
However, since the PocketPC is more than that, let’s take a look at developing a small application that can be used by any frequent traveler. This small app consists of a client application that will reside on the PocketPC device and will connect via the Internet to a Web server, which hosts data regarding different cities.
The application will perform the following tasks:
The PocketPC application will point to a Web service from where it will be getting all its data. |
Provide a simple client interface.
Show a list of cities that the application can serve. This list is refreshed/ obtained from a Web service.
When the user selects a particular city, the client app then gets a list of services, such as hotels, cinema halls, museums, art galleries and restaurants. This list too will be populated from a Web Service.
When a user selects a particular service, the address details of the items within this service will also be shown. Again the information will come from a Web service.
Creating the client application
For the purpose of this article, we shall create a very simple set of Web services, which we have given below:
GetCities: returns the list of cities that the service has data for.
GetServices: returns the list of services for a chosen city (takes CityID as parameter)
GetServiceItems: returns the list of items that come under a particular service.
Save the following as TravelGuide.ASMX in your Web folder. Make the appropriate changes to the connection string to connect to your database.
<%@ WebService Language=”vb” class=”TravelGuide” %>
Imports System
Imports System.Data
Imports System.Data.SQLClient
Imports System.Web.Services
Public Class TravelGuide
Inherits System.Web.Services.WebService
Public Function GetCities() as DataSet
Dim Conn as SQLConnection = New SQLConnection(“server=mobilexp\vsdotnet2003;database=Experiments;uid=sa;pwd=”)
Dim Cmd as SQLDataAdapter = New SQLDataAdapter(“Select * from tblCities”, Conn)
Dim DS as New DataSet
Cmd.Fill(DS, “Cities”)
Return DS
End Function
End Class
Open a new session of Visual Studio.NET 2003 and create a new Smart device application. This creates the files required to make a PocketPC application.
Create a drop down menu of the list of cities you want detailed information on. |
Now add a new Web reference to the project by right-clicking the project, selecting Add New Web Reference and pointing to the Web service. In this case, we shall point to the TravelGuide.ASMX folder on your local Webserver. Once the Web service is registered for use in the project, the rest becomes simple enough. Name the Web service as
TravelGuide.
Now drop a label control and a drop down control onto the displayed form in the Visual Studio.NET design window. Change the text of the form to display India Travel Guide, the text for the label to Cities and the name of the drop down to cmbCities.
Double click an empty part of the form to write the form’s Load even handler as follows:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim wsTravelGuide As New TravelGuide.TravelGuide
Dim ds As New DataSet
ds = wsTravelGuide.GetCities()
cmbCities.DataSource = ds.Tables(0)
cmbCities.DisplayMember = “sCity”
End Sub
This assumes, of course, the name of the Web service is TravelGuide and is added correctly to the project. The app connects to this Web service as the form loads and populates the data in the drop down accordingly.
This quick sample application shows you how to connect and consume a Web service from a PocketPC application.
However, the application is neither complete nor is it optimized. For instance, every time you run the app, it tries to connect to the Web service as well, doing it in such a way, that the app is locked till the Web service call returns. We shall take a look at how to change these behaviors in forthcoming articles on the PocketPC platform.
Vinod Unny is a Technology Consultant
At Enterprise InfoTech