DEVBUZZ Homepage Invoking the Google Web Service on your SmartPhone
 
Web www.devbuzz.com
  HOME PAGE
  All Articles
  Advertise
  Consulting

 Development
  Discuss - Forums
  Still in the box?
  .Compact Framework
  Code Snippets
  SQL Server CE
  Database
  MS Resources
 Stores
  Developer Controls
  Pocket PC Hardware
  Pocket PC Software
  Pocket PC Books
  .NET CF Books
  Book Reviews
  SPB SW Discounts
  RESCO SW Discounts
 DEVBUZZ Info
  About Us
  Help
  Join our email list
  Links & Ratings
  Press & Comments
  Pocket PC version
  Software Reviews
  Hardware Reviews
 Authors
  Authors
  Article Guide
  Competitions
 Resources
  Developers
  Register
  Login

  SPB Discounts!
 Columnists
  Rick Winscot
 Past Blast
  Personal Media Ctr
  Gizmobility
  eVB Legacy
  Old news
  Hosted Software
  Wireless
  Newsletters
  Carl Davis
  Upton Au

 Pocket PC Registry
  Join the registry
  View current list
 Current Poll
Are you converting to .NET Compact Framework?
Yes, it has changed my life!
No, I'm sticking with eVB
.NET CF what's that`?

Current results
3431 votes so far
 Recent Forum Threads [goto forums]

Get Computername
read... (67 hits)


Great aid to development productivity
read... (82 hits)


ThreadingTimer sample code
read... (143 hits)


Multithreading with .NET CF
read... (194 hits)


Moving from eMbedded Visual Basic to Visual Basic .NET
read... (166 hits)


.NET Compact Framework 2.0 Service Pack 2
read... (226 hits)


Transfer Data from SQL Server 2000 to SQL Server Compact Edition
read... (298 hits)


This protocol version is not supported
read... (236 hits)


Converting Lowercase to uppercase wont work
read... (203 hits)


Direct access to MS SQL Server 2000
read... (374 hits)


Creating SDF file in Desktop
read... (513 hits)


Winsock in CF.NET
read... (316 hits)


Using Pocket Outlook to submit HTML page form with MAILTO action
read... (420 hits)


Missing file "System.Data.PocketPC.asmmeta.dll"
read... (268 hits)


HP iPAQ hw6915 Serial Port Issue
read... (309 hits)


Info on the recent forum changes
read... (341 hits)


SqlServer tools from Redgate
read... (383 hits)


Arrow keys and Hardware navigation button
read... (393 hits)


O2 XDA lls pin sync cable to comport
read... (322 hits)


Creating dynamic folders on Pocket PC OS
read... (299 hits)

Custom Windows Mobile software development.
LBS Challenge 2007
LBS Challenge Eight previous NAVTEQ Global LBS Challenge® participants have received venture capital funding and nine past LBS Challenge winners have launched commercial applications on major wireless carriers. Register your non-commercial LBS application in the 2007 NAVTEQ Global LBS Challenge in one of three regions: Americas, Europe-Middle East-Africa (EMEA) or Asia-Pacific(APAC). You could win a share of $2 million in prizes. This could be your year.
Dream. Develop. Win.

Development | .NET Compact Framework

Invoking the Google Web Service on your SmartPhone
Written by W.G. Ryan  [author's bio]  [read 20265 times]
Edited by Derek

eVB Ver 3.0   

Page 1 

It's hard to imagine that any software developer hasn't heard of Google. What you may or may not be familiar with is their APIs. The first thing you need to do is register for the service. They'll give you 1,000 requests a day which is more than enough more for non-commercial application. If you need more I can't help you though b/c I wasn't able to find the pricing for it (by the time you're done reading though, maybe you can invoke a Google Search for their prices with your Smartphone). Registration is really easy and it's basically no different from every other sort of service you register for.

Ok, now I have to warn you about a few things. The Smartphone isn't the same thing as your desktop. The framework is called "Compact" for a good reason. This is obscured by the fact that in many instances, the code is identical to it's desktop counterpart. Don't lost sight of that fact though. You are in a resource constrained environment and there's no room for inefficient code. There aren't 50 events for every control nor are there a lot of controls in comparison to the desktop. Nor should there be, it just wouldn't make much sense.

I don't want to get into the guts of web services and how they work, but in a nutshell, it's pretty much the same as the desktop. Now, XML isn't the fastest way to access data and in most instances (particularly on a SmartPhone) it is pretty slow. So why am I using it?  Well, for one thing you don't have many alternatives on the Smartphone platform. For another it's Google's primary method of exposing its web service/API..

To set things up, I'm going to create a basic Smart Device Application and target it to the Smartphone platform. Once you do this, you should see a small form appear in your IDE. Its size and unique look clearly indicate you are targeting the Smartphone platform. Like I mentioned, you don't have all of the controls you are used to and the ones that do exist expose notably different functionality than you're probably used to dealing with. As such, I'm going to use a CheckBox control in place of where I'd typically use a CommandButton. When the user clicks on the checkbox, I'll examine its CheckState property and if it's checked, I'll fire my search.

Since querying Google wouldn't be of much value unless you can dynamically specify your search criteria, I'm going to include a TextBox control so the user can provide their search terms. Finally, once the service is invoked, I'll use the ComboBox control to load the results provided there are any. Once you have your controls loaded, you could easily expand this to do other things with your results. Air Time isn't cheap in most cases so this isn't economically the best way to hit data, but like I mentioned before, your data access options are limited on the Smartphone and invoking web services is one of your few options. Also note that you can easily load/read xml using System.Data which has a really strong implementation even on this platform. Anyway, let's go grab some data.

The first thing we need to do after we've registered for the service is to add a Web Reference to your project. In your Solution Explorer, right click References and choose the 'Add Web Reference' option. You can plug in http://api.google.com/GoogleSearch.wsdl to the URL box provided. At this point, Visual Studio .NET should create a proxy class for you provided it was able to see the .wsdl. It will probably call the proxy something like com.google.api. After this is created, the behavior you should see is virtually identical to any other class you would use or reference. If you look in the Object Browser ->  YourProject.com.google.api you - you'll see 4 classes (DirectoryCategory, DirectorySearchResult, DirectorySearchService & ResultElement). If you see those everything is good to go. Basically, to invoke and use Google's api, this is pretty much all there is to it

private void checkBox1_CheckStateChanged(object sender, System.EventArgs e)
{
          if(!checkBox1.Checked)return;
          com.google.api.GoogleSearchResult searchResult = new com.google.api.GoogleSearchResult();
          com.google.api.GoogleSearchService g = new com.google.api.GoogleSearchService();
          searchResult = g.doGoogleSearch("KeyHere", tbCriteria.Text , 0, 9, false,string.Empty,false, string.Empty, string.Empty, string.Empty);
     foreach(com.google.api.ResultElement re in searchResult.resultElements)
    {
      cboResults.Items.Add(re.URL);
     }
}
 
 
All that's really happening here is checking if the user actually wants to call the web service and if they do, I instantiated a new instance of a SearchResult, fire the service using my private key using doGoogleSearch and then iterate through the results. As I mentioned, there are 3 other classes you can manipulate w/ the API directly, but there's a TON of stuff within each of those. In addition, just like there's doGoogleSearch, there's an Async invocation called BegindoGoogleSearch following .NET's naming convention for async calls.

This is just a really basic intro into using the Google API but it lays the ground work for my next article, integrating the XML features of Infopath, XML Webservices and the Compact Framework

Back to .NET Compact Framework | [Article Index]

 

Back to the top of the page.
Chris De Herrera's Windows CE Website Windows CE News & Information Source
Copyright ©2000-2007 by DEVBUZZ.COM, Inc., NJ. USA.MSDEVELOP