| ||
|
The beauty of a Web Service is that it is implemented using a common standard, based on XML, that specifies how to call it, what it needs as input and the response format. As Web Services become increasingly popular among developers and system integrators users will be able to get much more out of their connected mobile devices, such as the Pocket PC Phone Edition. Getting Directions by Knowing Phone Numbers If you know the phone number for the place at which you are, and the phone number for the place to where you wish to go, then you can use the sample application Directions Anyplace to get directions between the two places. You can download this article's sample code. I combine two publicly available Web Services and have put together a sample application called Directions Anyplace using them. The main Web Service connects to MapQuest and retrieves driving directions between two US addresses. The supporting Web Service retrieves two addresses by using the two phone numbers entered by the user. This Web Service is provided by ServiceObjects. The figure below shows the user interface, implemented in one form. The user enters any US phone number in a digit-only format (xxxxxxxxxx). In this example, I want to go from the Pike Place Market to the Experience Music Project, both attractions in Seattle. ![]() Directions Anyplace sample When the user has entered one "from-phone number" and one "to-phone number", the Pocket PC applications retrieves the to addresses and passes them to the supporting Web Service. The result is driving directions between the two places! As you can see, you even get the addresses two both attractions before the driving directions! Code Walkthrough First, you need to add the two Web references to the external Web Services to the project. The code behind the application "Directions Anyplace" is implemented behind the Click event of the Find button (see figure above). To ease the use of the Web Services, the following code was added: using Directions_Anyplace.net.serviceobjects.ws; using Directions_Anyplace.com.borland.ww6;The Web Services are referenced according to the following: // Instantiate Web Services GeoPhone geoPhone = new GeoPhone(); IMapQuestservice directions = new IMapQuestservice();The wait cursor is made visible before the calls to the Web Services. The address Web Service is called twice and results in two phone contact objects. The contact objects contain the name and address information for each entered phone number.
// Show wait cursor
WaitCursor.Show(true);
try
{
// First Web Service calls! Get two addresses!
Contact contactFrom = geoPhone.GetPhoneInfo(txtFromPhone.Text,
"0").Contacts[0];
Contact contactTo = geoPhone.GetPhoneInfo(txtToPhone.Text,
"0").Contacts[0];
Once the addresses are retrieved, it is time to call the driving directions Web Service!
// Second Web Service call! Get directions!
txtDirections.Text = directions.GetDirections(contactFrom.Address,
contactFrom.City, contactFrom.State, "US", contactTo.Address,
contactTo.City,contactTo.State, "US");
}
catch
{
MessageBox.Show("Could not make Web Service calls!");
}
finally
{
WaitCursor.Show(false);
}
Finally, we handle any problems that have arisen and remove the wait cursor.
Conclusion This example shows how easy it is to combine Web Services and make the results available on a connected Pocket PC. I believe we will soon see more connected Pocket PC users using Web Service powered applications. Wouldn't it be a perfect world!? No one will ever get lost again! Any comments? |
||||||||||||||||||||||||||
| ©2001-2009 Christian Forsberg & Andreas Sjöström |
||