Library tutorials & articles
Implementing The Google Web Service In VB.NET
- Introduction
- The Google Web Service
- Implementing the Web Service
- Conclusion
Implementing the Web Service
In the solutions explorer window, click on the web reference to see the Google web reference that we added earlier. Let's rename it to Google, by right clicking on it and clicking rename:
Create a user interface as shown in the image below. Add the following controls:
- For searching:
txtSearch- TextBoxlbl_TotalFound- Labelbtn_Search- Button - For spell checking:
txt_CheckSpelling- TextBoxlbl_CorrectSpelling- Labelbtn_CheckSpelling– Button
Type the following code into the click event of the Google search button (btn_Search):
Private Sub btn_Search_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btn_Search.Click
Dim MyLicenseKey As String
' Variable to Store the License Key
' Declare variable for the Google search service
Dim MyService As Google.GoogleSearchService = New _
Google.GoogleSearchService()
' Declare variable for the Google Search Result
Dim MyResult As Google.GoogleSearchResult
' Please Type your license key here
MyLicenseKey = "tGCTJkYos3YItLYzI9Hg5quBRY8bGqiM"
' Execute Google search on the text enter and license key
MyResult = MyService.doGoogleSearch(MyLicenseKey, _
txtSearch.Text, 0, 1, False, "", False, "", "", "")
' output the total Results found
lbl_TotalFound.Text = "Total Found : " & _
CStr(MyResult.estimatedTotalResultsCount)
End Sub
Type the following code into the click event of the check spelling button (btn_CheckSpelling):
Private Sub btn_CheckSpelling_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btn_CheckSpelling.Click
Dim MyLicenseKey
As String ' Variable to Store the License Key
' Declare variable for the Google search service
Dim MyService As Google.GoogleSearchService = New _
Google.GoogleSearchService()
' Declare variable for the Google Search Result
Dim MyResult As String
' Please Type your license key here
MyLicenseKey = "tGCTJkYos3YItLYzI9Hg5quBRY8bGqiM"
' Execute Google search on the text enter and license key
MyResult = MyService.doSpellingSuggestion(MyLicenseKey, _
txt_CheckSpelling.Text)
' output the Results
lbl_CorrectSpelling.Text = "Did you Mean : " & MyResult
End Sub
Now that we have finished coding our application, run the application and type some text into the search box and click on the google search button to see number of results found. Also test out the Google spell check. And there you have it! Our web service is working as planned, and only with the implementation of a couple of lines of code!
Related articles
Related discussion
-
VB.NET Simple Client / Server Communication
by r0bbyw (3 replies)
-
How to write the category attribut in a class dynamically
by converter2009 (1 replies)
-
VB.NET: Hide and show table using radio buttons
by converter2009 (1 replies)
-
VB.Net Button Problem
by pysdex (0 replies)
-
Unable to access AxInterop.AcoPdflib.dll on 64 bit OS
by Shaila14041981 (0 replies)
Related podcasts
-
Introduction to Atlas
Get your feet wet with an introduction to Atlas. Atlas is the new part of the .NET framework specifically for web clients. Features include AJAX and web services support, new validation controls, behaviors, and an object orientation layer sitting on top of JavaScript.
Events coming up
-
Dec
8
December Silicon Valley Ruby Meetup
Moffett Field, United States
In a World of Middleware, Who Needs Monolithic Applications? by Jon Crosby With Rack emerging as the standard for composing web applications and services, most recently with Rails adoption, an architectural shift is taking place. Learn how to create next generation web services by reusing existing Rack middleware and supplementing with your own components and micro-frameworks like Sinatra. Bio : Jon likes music, the Open Web, Ruby, Erlang, Haskell, Objective-C, JavaScript and coffee.
I tired this in Visual Basic 9.0 .net 3.5 the code is slightly modified details are given below,
Public Class Google_Search
' for Google Search button
Private Sub BtnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSearch.Click
Dim MyLicenseKey As String
' Declare variable for the Google search service
Dim MyService As GoogleReference.GoogleSearchPort = New GoogleReference.GoogleSearchPortClient
' Declare variable for the Google Search Result
Dim MyResult As GoogleReference.GoogleSearchResult
' Please Type your license key here
MyLicenseKey = "tGCTJkYos3YItLYzI9Hg5quBRY8bGqiM"
' Execute Google search on the text enter and license key
MyResult = MyService.doGoogleSearch(MyLicenseKey, _
TxtSearch.Text, 0, 1, False, "", False, "", "", "")
' output the total Results found
LblTotalFound.Text = "Total Found : " & _
CStr(MyResult.estimatedTotalResultsCount)
End Sub
'For name search button
Private Sub BtnCheckSpelling_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCheckSpelling.Click
Dim MyLicenseKey As String
' Declare variable for the Google search service
Dim MyService As GoogleReference.GoogleSearchPort = New GoogleReference.GoogleSearchPortClient
' Declare variable for the Google Search Result
Dim MyResult As String
'Please type in your key here
MyLicenseKey = "tGCTJkYos3YItLYzI9Hg5quBRY8bGqiM"
' Execute Google search on the text enter and license key
MyResult = MyService.doSpellingSuggestion(MyLicenseKey, TxtCheckSpelling.Text)
'Output Results
LblCorrectSpelling.Text = "Did you mean: " & MyResult
End Sub
End Class
With a huge pleasure I've found this article. Thank you.
This thread is for discussions of Implementing The Google Web Service In VB.NET.