Export (0) Print
Expand All

Combining Web Services and Pocket PC Phone Edition to Create Value

.NET Compact Framework 1.0
 

Andreas Sjöström
businessanyplace.net

April 2003

Applies to:
   Microsoft® .NET Compact Framework
   Pocket PC Phone Edition

Summary: Understand how to make use of the growing number of Web services using your mobile device and the .NET Compact Framework. (4 printed pages)


Download booksanyplace.exe.

Contents

Mobility Meets the New Web
Find Those Web Services
Combine Web Services to Create Value
Meet the Books Anyplace Application
Walking Through the Code
Conclusion
References

Mobility Meets the New Web

At the core of almost every piece of the .NET Framework we find XML. This is true also for the implemented distributed computing model. Web services have become the foundation for making application logic available to users and other applications. In reality, a new generation of the Web is slowly growing up: a new Web that is built using Web services. The .NET Compact Framework which is used to enable .NET applications on Pocket PCs supports Web services natively. With the connected Pocket PC Phone Edition mobility meets the rich functionality of the new Web.

Find Those Web Services

A number of sites on the Internet focus on collecting, categorizing and making Web services available to application developers. If you are looking for Web services to mobilize, I recommend salcentral and Xmethods.net. You can even combine the use of several Web services to provide a more useful application feature set.

Combine Web Services to Create Value

I will walk you through the steps of making two Web services work together, and thereby adding extra value to the user. As an example, I choose to use a Web Service that returns the price of a book at BN.com given an ISBN number (Book Web Service) and a Web Service that converts currencies (Currency Web Service). The idea is to put together an application that converts the US dollar amount returned by the Book Web Service, convert the US dollar amount to other currencies using up-to-date exchange rates returned by the Currency Web Service.

A user with an application like this running on a Pocket PC Phone Edition can always make sure she gets the best or at least a good price when out book shopping in book stores. Users living outside the US are likely to find the conversion aspect more useful than those living in the US. However, US users will find just the book price look up quite useful. Personally, I believe that applications that enable consumers to become more educated about the products they need and want are ideal mobile applications.

Meet the Books Anyplace Application

The Books Anyplace application uses only one form. The user enters an ISBN number, selects a currency in the list and then clicks the Get Price button.

Figure 1. Enter ISBN and select currency

The two Web services are put to work and eventually the responses from both of them have come through. The ListView is updated with the results.

Figure 2. Book price in US dollar and in selected currency

Walking Through the Code

Let me first introduce you to the two Web services used in Books Anyplace. Both Web services are listed as demo Web services at Xmethods.com.

Book Web service

Description: Returns price of a book at Barnes & Noble (BN.com) given an ISBN number.

Location of the WSDL: WSDL Document

More information: Xmethods.com

Currency Web Service

Description: Exchange rate between any two currencies.

Location of the WSDL: WSDL Document

More information: Xmethods.com

Adding a Web Reference to the project

It is almost scary how easy it is to add a Web Reference (reference to a Web Service). Just enter the path to the WSDL document and you’re done. Once you’ve added the necessary Web References, the rest is equally straightforward. The following code snippet illustrates everything that happens after the user clicks the Get Price button.

private void btnGet_Click(object sender, System.EventArgs e)
{
// Get the price and convert it!
// Known bugs:
// Version   Date   Who Comment
// 00.00.000 020808 ASJ Created
// *****************************

// Start the hourglass 
WaitCursor.Show(true);

try
{

// Declare the Book Web Service
net.xmethods.www.BNQuoteService BNQuote = new net.xmethods.www.BNQuoteService();

// Get the price
float price = BNQuote.getPrice(txtISBN.Text);

// Declare the Currency Web Service
net.xmethods.www1.CurrencyExchangeService Currency = new net.xmethods.www1.CurrencyExchangeService();

// Get the converted price.
float rate = Currency.getRate("us", cmbCurrency.Items[cmbCurrency.SelectedIndex].ToString());

// Multiply the $US price with the exchange rate.
decimal convertedPrice = (decimal) (price * rate);

// Round the results
convertedPrice = Math.Round(convertedPrice, 2);

// Add to ListView
ListViewItem lvi = new ListViewItem(txtISBN.Text);
lvi.SubItems.Add(price.ToString());
lvi.SubItems.Add(convertedPrice.ToString());
lvi.SubItems.Add(cmbCurrency.Items[cmbCurrency.SelectedIndex].ToString());
lvwBooks.Items.Add(lvi);

}
catch
{
MessageBox.Show("Could not call Web services!", this.Text);
}
finally
{
WaitCursor.Show(false);
}
}

If this is not supporting Web services natively, I don’t know what is. Visual Studio® .NET exposes the Web services as a .NET class and you use it just as such. In fact, apart from the code handling the user interface and class initializations, there is just one line of code each to get the Web services running on the Pocket PC Phone Edition.

Conclusion

I hope this article explains how to get going in mobilizing Web services. Combined with the connectivity of the Pocket PC Phone Edition you can let those Web services move absolutely freely.

References

If you would like to learn more about Web services, I recommend the following sites:

Show:
© 2014 Microsoft