Calling Web APIs from Pocket PCApplicationsIn this section, you create two sample mobile device applications using Visual Studio .NET 2003. Theseexamples illustrate how easy it is to use the APIs covered earlier in this book in mobile applications. Thefirst example uses the MapPoint API and the SOAPProtocol to retrieve specified driving directions. Thesecond example uses the Amazon.com API to retrieve a list of books matching specified search criteria. You don t need a Pocket PC in order to run these examples because VS .NET has emulators that allowyou to test the application without an actual device. Before actual deployment, however, you should teston an actual device. Example 1 Call MapPoint API Using SOAP Protocol to Retrieve Driving DirectionsIn this example, you use the MapPoint API to get driving directions. MapPoint is covered in detail inChapter 3. Let s get started by creating the application to run on a Pocket PC. 1.Open Visual Studio .NET and select File.New.Project. 2.Select Visual Basic Project as the Project Type, and select Smart Device Application as the Template. For the project name, specify PocketPCTest, and for the path specify the location where you wantthe project to be created. This is illustrated in Figure 8-1. Click OK to create the new project. Figure 8-13.The Smart Device Application Wizard appears, as shown in Figure 8-2. Select Pocket PC andWindows Application and click OK. 184Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
Figure 8-24.Anew Pocket PC project is created, with the default form sized according to the standard device. 5.Use the toolbox to drag and drop two labels, three text boxes, and a button control onto the 6.Using the Properties window, change the Name property of the first text box totxtStartingAddress, the Name of the second text box to txtEndingAddress, the Nameproperty of the third text box to txtResults, and the Name property of the button tobtnRetrieve. Modify the MultiLineproperty of txtResultsto True. Rename the Textproperty of the labels as shown in Figure 8-3. Figure 8-3185Calling
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
has been designed, it is pretty easy to use that same code for both Pocket PCs and Smartphones. As rule, approximately 85 percent of the code is the same between a Pocket PC version of a programand the Smartphone version of the program; and in most cases, the differences occur because of changesto accommodate the user interface. Visual Studio .NET 2003 and later versions have what is referred to as Smart Device Programmability(SDP)features. What this really means is that the .NET Compact Framework has been integrated withVS .NET 2003 and comes preinstalled. For Visual Studio .NET 2002, you have to download the .NETCompact Framework separately and install it. Later in this chapter, you create two sample mobile deviceapplications using Visual Studio .NET so you can see how this works. When you want to write native applications that are optimized in memory and speed, you may chooseto use a language such as C++ or Visual Basic. At other times, you may want to write a mobile deviceprogram without using Visual Studio .NET. Microsoft offers eMbedded Visual Toolsto allow you to createapplications in a separate environment from VS .NET. The eMbedded Visual Tools come with the neces- sary compilers, debugging tools, and documentation, and they can be downloaded for free from theMicrosoft Web site. For more information about the .NET Compact Framework and eMbedded Visual Tools, visit the follow- ing Microsoft Web site: http://msdn.microsoft.com/mobility/windowsmobile/default.aspx. Palm and Other DevicesPalm devicesare those that run the Palm operating system, as opposed to a Microsoft Windows operatingsystem. According to some statistics, Windows Pocket PCs have surpassed Palm devices in popularity. One reason is probably because Microsoft has made it easy to develop applications on Pocket PCs a task that is typically much more difficult on a Palm device. This trend is changing. and Web services have become more important, substantial improvements have recently madeit easier to develop Web-enabled programs that run on a Palm device. As one example, Palm Solutions Group has released a Web Services for Palm (WSP) programthat allowsyou to write Java or C programs for a Palm device that calls Web services. The WSPprogram providessupport for SOAP, XML, HTTP, and other Web services concepts. WSPreads the WSDLfile of the Webservice and generates the necessary code to enable your application to communicate using SOAP. Thistool performs a function similar to adding a Web reference from within Visual Studio .NET. More information about the Web services for Palm programs can be found at http://pluggedin. palmone.com/regac/pluggedin/WebServices.jsp. IBM has introduced a Web Services Tool Kit for Mobile Devicesthat enables you to develop mobile applica- tions that use Web services. The toolkit includes a Java Web service runtime environment that is sup- ported on any device that supports the Java 2 Micro Edition (J2ME), WCE, and SMF environments. also includes a C Web service runtime environment that is supported on any Palmor Symbiandevice. You can download the toolkit at http://www.alphaworks.ibm.com/tech/wstkmd. Developers can use IBM s WebSphere Studio Device Developer (WSDD) as a graphical developmentenvironment for J2ME mobile applications. More information on WSDD can be found at http:// www-306.ibm.com/software/wireless/wsdd/?Open&ca=daw-prod-wstkmd. Now that you have an idea of the various options available for calling Web APIs from mobile devices, let s walk through a couple of examples to see this in action.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
In order for these devices to take advantage of XMLWeb APIs, the following criteria must be met: .The device must be updateable so that developers can write applications that run on the device. .The device must be able to access the Internet because Web APIs are called over the Internet. .The device must support the capability to communicate using SOAP, HTTP/POST, and/orHTTP/GET (REST), depending on the type of Web API you want to use. In most cases, if the device is capable of connecting to the Internet, it can communicate using SOAP, HTTP/POST, and/or HTTP/GET. However, on some devices, the only way to implement such commu- nications is to write a lot of code yourself to implement the communication protocols. On newer devices, such as those running Windows Mobile 2002 or 2003 for Pocket PCs or Smartphones, software develop- ment tools make this process easy. Let s look at Pocket PCs and Palm devices in more detail. Windows Pocket PCs and SmartphonesThere seems to be a lot of confusion of terminology when it comes to personal digital assistants. Forexample, many people use the terms Pocket PC and Smartphone to mean the same thing. There are dis- tinct differences between these terms. APocket PCruns a smaller version of Microsoft Windows, such as Windows Mobile 2002 or 2003 forPocket PCs. These operating systems are often called Pocket PC 2002 or Pocket PC 2003. Pocket PCs typ- ically have a larger screen and focus on the PDAfunctionality, although they may also have an inte- grated phone. Pocket PCs enable you to manage your contacts, calendar, and tasks; surf the Internet; plus run mini versions of programs such as Microsoft Word and Microsoft Excel. ASmartphone, on the other hand, runs Windows Mobile 2002 or 2003 for Smartphones, also calledSmartphone 2002 or 2003. Smartphones typically have a smaller screen and focus on the phone function- ality, although they also have integrated PDAfeatures. Smartphones allow you to access your contacts, calendar, and tasks, and surf the Internet, but they cannot run programs such as Microsoft Word orMicrosoft Excel. You can find more general information about the Windows Mobile operating system for both Pocket PCsand Smartphones at www.microsoft.com/windowsmobile. With the latest version of the Microsoft development tools, such as Visual Studio .NET 2002 and 2003, you can easily write programs that will run on newer Pocket PCs or Smartphones that can run the .NETCompact Framework, such as those running Windows Mobile 2002 or 2003. Furthermore, you can alsoenable those mobile device applications to call Web APIs, as long as they have an Internet connection. The .NET Compact Framework provides rich support for XML, SOAP, and other Web services concepts. As you have already learned in earlier chapters, calling a SOAPWeb service can be as easy as adding aWeb reference to the Web service WSDLlocation and then working with the service in your code. The.NET Compact Framework works the same way. The .NET Compact Framework enables you to write programs in Visual Basic .NET or C# using thesame tools and techniques as you do for desktop programs that use the .NET Framework. What is greatabout using Visual Studio .NET is that you can write the application one time for the desktop, and thenuse a large portion of that same code to write one or more mobile versions of the program to run on aPocket PC and/or Smartphone. Because of the memory, database, and screen-size limitations imposedby mobile devices, you usually have to rework some of the code. After a mobile version of a program182Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
Calling Web APIs fromMobile DevicesWith today s focus on a mobile lifestyle, it is becoming increasingly popular to have access to thesame tools on a personal digital assistant (PDA) as you do on a desktop computer. So far in thisbook, you have explored several leading XMLWeb APIs and have looked at how to call those APIsfrom desktop applications. In this chapter, you learn how to call these Web APIs from a mobile orembedded device, such as a Windows Mobile Pocket PC or a Palm device. This chapter specifically covers the following: .Calling an XMLWeb service from a Windows device .Calling an XMLWeb service from a Palm device .Creating a sample .NET pocket PC application that calls a Web API using the SOAPprotocol .Creating a sample .NET pocket PC application that calls a Web API using HTTP/GET (REST) .Using an emulator to test the applicationWhat Devices Support XML Web APIs? Hundreds of mobile and embedded devices are in circulation today, ranging from personal digitalassistants that are handheld, palm size, or even the size of a watch. Many mobile devices havephone and PDAfunctionality integrated in one device. Devices can also be embedded into otherdevices, such as a computer integrated within an appliance or automobile, to name a few exam- ples. Many of these mobile or embedded devices are capable of calling the XMLWeb APIs youhave explored throughout this book.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
Locating Additional Web APIsYou can find which Web service APIs are available in various ways, such as searching the Internet forvarious Web services listings. Unfortunately, no one-stop shop lists them all. Microsoft and IBM startedthe effort some years ago of creating a directory of Web services called Universal Description, Discovery, and Integration (UDDI). The idea behind UDDI is to provide a central directory, like a phone book, forlocating available Web services. UDDI has not caught on as quickly as expected, mostly because Web services were not adopted by theindustry as quickly as everyone expected. At this point, now that there are several leading vendorsreleasing Web APIs, the UDDI directory is gaining popularity. Thus, if you are searching for availableWeb services, one place to visit is http://uddi.microsoft.com. You then can click the search optionon the navigation pane to perform a search. Figure 7-11 is an example that illustrates the Web services that Amazon has listed with the UDDI serviceat the time of this book s writing. Figure 7-11178Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
Although the UDDI directory does not contain every Web service available, it is a good place to startwhen you want to find out what companies are offering. Another directory I like to use can be found at http://www.bindingpoint.com. As shown in Figure7-12, the site allows you to browse Web services by categories or search the database based on keywords. Figure 7-12This page feels more like an on-line portal. Bindingpoint.com includes links to top-rated Web services, new services, and more, as shown in Figure 7-13. As you can see, Bindingpoint.com is a very useful site that you should bookmark for later use, althoughit does not contain all Web services available. You may still need to use other sources to locate availableWeb services, such as a search engine like good ol Google!
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
Create an HTTP Web Request objectDim req As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create( FedExSSLHostURLGoesHere ), System.Net.HttpWebRequest) req.Method = POST req.Referer = YourCompanyName req.Accept = image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */* req.ContentType = image/gif req.ContentLength = Len(APITrans) Dim reqstream As System.IO.StreamWriter = NewSystem.IO.StreamWriter(req.GetRequestStream()) write the transaction to the stream - i.e. submit to serverreqstream.Write(APITrans) reqstream.Close() get the response from the serverDim resp As System.net.HttpWebResponse = CType(req.GetResponse(), System.Net.HttpWebResponse) declare a stream to read the resultsDim sr As New System.IO.StreamReader(resp.GetResponseStream) Dim strResponse As String read the entire stream to retrieve the resultsstrResponse = sr.ReadToEnd display the resultsMsgBox(strResponse) For more information about the FedEx Ship Manager Direct tool, please consult the documentationavailable on the FedEx Web site, including the FedEx Ship Manager Direct Programmer s Guide. Bloglines Web APIBloglines is a company that offers free online news feed and blogging services, including searching, sub- scribing, publishing, and sharing (www.bloglines.com) news feeds and blogs. At the time of thisbook s writing, Bloglines just released new Web services in beta version that are called the Bloglines WebServices (BWS). The Bloglines Web Services (BWS) enable you to access subscription and feed data fromwithin your own programs. BWS is a Web service that can be called using HTTP-GET/REST. As youlearned in the earlier chapters, including Chapter 1, REST APIs are invoked by sending URLs that con- tain the parameters. To find out more information about the Bloglines Web services, go to http://www.bloglines.com/ services/. Ascreen similar to that shown in Figure 7-9 is displayed. You can then learn more about the methods available in the APIs by visiting http://www.bloglines. com/services/api/or clicking the Documentation link shown on the screen in Figure 7-9. Ascreensimilar to that shown in Figure 7-10 is displayed that describes the methods available in the Web servicesand the third-party implementations that are also available. 176Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services