16.5 More kSOAP ExamplesIn this section, let's check out two kSOAP applications for real-world services. 16.5.1 The Google Web Services API DemoIn the previous sections, we demonstrated how to invoke a simple Google spell check Web Service. In fact, Google offers much more than the simple service. With a proper Google ID (free registration), we can use the Google Web Services interface to search the Web and get any Web site's Google cache. I developed a complete Google API toolkit based on kSOAP. The toolkit and its MIDP UI driver are available for download from this book's Web site (see "Resources"). The Web search service has the most complex interface. The response SOAP document has three arrays of equal length: They contain the search result sites' URLs, titles, and cache sizes respectively. We can use a Java data object SearchResults to encapsulate the Google search results (see Listing 16.11). Listing 16.11. Class SearchResults encapsulates the Google search results
Listing 16.12 demonstrates how to send out a search query and marshal the response to a SearchResults object. Listing 16.12. Google search
16.5.2 SmartPhrasesSmartPhrases is a mobile dictionary and thesaurus, smart spelling checker, and real-world usage checker. It is an award-winning application developed by Ju Long and Michael Yuan. Its source code is freely available from this book's Web site.To be able to access dictionaries from devices, SmartPhrases includes a SOAP dictionary gateway. The gateway connects to free Internet dictionary servers using the TCP/IP-based DICT protocol. It then exposes dictionary query services through a simple SOAP interface using Apache Axis. Any mobile or desktop SOAP client can access the backend dictionary from the gateway service.SmartPhrases utilizes Google Web Services to go beyond simple dictionaries: Google allows the user to check the usage of a phrase in real-world scenarios; it has a modern vocabulary list and makes spell suggestions for the entire phrase. The architecture of the application is shown in Figure 16.3. Figure 16.3. The architecture of the SmartPhrases application.![]() For a complete demo and implementation documentation of SmartPhrases, please download its source package. |