Click here to Skip to main content
Click here to Skip to main content

Using a Web Service in VB.NET

, 11 Mar 2003
Rate this:
Please Sign up or sign in to vote.
Article shows creation of a webservice using VB.Net and Google

Introduction

Web services are one of the greatest technologies developed in the Internet world, which could be used to connect businesses with each other and clients in a standard way using XML (Extensible Markup Language), SOAP (Simple Object Access Protocol), WSDL (Web Services Description Language) and UDDI (Universal Description, Discovery and Integration).

XML is used for structuring the data, SOAP is used to transfer the data, WSDL is used for describing the services and UDDI is used to get a list of services available. Web service allows application to communicate with each other without worrying about their hardware systems, operating systems and programming languages.

Unlike the older model, web service does not provide a user interface but exposes the business logic, which can be programmed, and hence the user is free to add his own interface to the application.

Google is one of the website which has provided with a public web services allowing application to use feature like search and spell checks. We shall now see how can we use this services in our application using Visual Basic.NET.

But before we could access Google web APIs service we will have to create an Google account and obtain an license key which shall allow us to run about 1000 automated queries a day. Please visit http://www.Google.co.nz/apis/ to create a Google account and once you have entered your email and password, Google shall mail you a license key, which we could use in our application.

Getting Started

Now that you have received your license key, we shall create an application in Visual Basic .NET to create a customized search and a spelling checker using Google Web APIs Service.

Open your Visual Studio .NET, create a new Windows Application Project, which we shall call googleapi, click OK.

Adding Web Reference to Google Web APIs Service

We shall now add a Web Reference to Google Web APIs Service, well this is almost like adding a reference to a COM/ActiveX objects, but when we add a Web Reference we now have access to all the XML web service on Google server. Open your Solution Explorer, right click the References and click Add Web Reference, alternatively you could select Project menu and click Add Web Reference.

In the window Add Web Reference type http://api.Google.com/GoogleSearch.wsdl in the address bar (please make sure you type exactly as show, as this URL is case sensitive)

After you enter the URL and press Enter and the Google Web Service is loaded you should see screen like Figure 2 also the Add Reference button is enabled, click Add Reference button to add this web reference to our project.

In the Solution Explorer Window click on the Web Reference to see a Google Web Reference, which we have added, lets rename that to Google by right clicking on it and clicking Rename.

Create a User Interface as shown below with the flowing controls and given names

a) For Searching on the Engine
txtSearch              - TextBox
lbl_TotalFound          - Label
btn_Search             - Button

b) For Checking Spelling

txt_CheckSpelling     - TextBox
lbl_CorrectSpelling     - Label
btn_CheckSpelling     - Button

Source Code

Type the following code in 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 in 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

Finally

Now we have finished coding our application, run the application now and type some text to search in the text box and click Google Search button to see number of results found also try Google spell check.

Now you must have realized how simple it is to incorporate Google Web APIs Service in your application, here are few things you could do with this service

  • Issuing regularly scheduled search requests to monitor the web for new information on a subject.
  • Performing market research by analyzing differences in the amount of information available on different subjects over time.
  • Searching via non-HTML interfaces, such as the command line, pagers, or visualization applications.
  • Creating innovative games that play with information on the web.
  • Add Google spell-checking to an application.

Few more things I would like to say before I sign off.  Google Web APIs support the same search syntax as the Google.com site and provides each developer who registers to use the Google Web APIs service a limit of 1,000 queries per day.

Please visit http://www.google.com/apis/api_faq.html if you have further question about Google Web APIs Service.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Jayesh Jain
Business Analyst
New Zealand New Zealand
Working as a Business Analyst for a leading software development organization in New Zealand. I have several years of n-Tier software development experience, about 10+ years in health sector and more than a year in graphics art industry. I am interested in Business improvement process, documentation and knowledge retaining strategies.

Comments and Discussions

 
NewsStill a VERY useful example!!! The WSDL is available!!! PinmemberMuzietto17-Oct-11 1:30 
QuestionHow do schedule a webservice created in vb.net and pull in oracle records? Pinmemberaispg86-Apr-11 3:35 
GeneralNo longer API keys for SOAP Search API... Pinmemberluisnike1919-Jun-09 12:03 
QuestionHow to create new account Google web APIs service ? Pinmembersanthakumara4-Mar-09 21:26 
GeneralError trying to Add a Web reference PinmemberVuyiswamb2-Nov-07 3:51 
GeneralMining Google Web Services: Building Applications with the Google API PinsussAnonymous21-Aug-05 20:47 
GeneralThe request failed with HTTP status 404: Object Not Found Pinsussanonymous4-Feb-05 19:11 
GeneralRe: The request failed with HTTP status 404: Object Not Found PinmemberMohammed G17-Sep-10 18:55 
They have removed this service. However, they allow this through javascript.
 
See http://forums.asp.net/t/1474317.aspx[^]
GeneralAccess Denied messge is coming PinmemberDeependra4-Apr-03 22:08 
QuestionDo I need to be online always? PinsussVicky271025-Mar-03 0:47 
AnswerRe: Do I need to be online always? PinmemberDaniel Turini25-Mar-03 1:27 
GeneralRe: Do I need to be online always? Pinmembervivek271025-Mar-03 16:57 
GeneralRe: Do I need to be online always? PinsussAnonymous11-Jun-03 7:13 
GeneralMisleading Title... PinmemberPaul A. Howes12-Mar-03 3:34 
GeneralRe: Misleading Title... Pinmemberector12-Mar-03 7:34 
GeneralRe: Misleading Title... PinadminChris Maunder12-Mar-03 10:15 
GeneralRe: Misleading Title... PinsussAnonymous19-Mar-03 21:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 12 Mar 2003
Article Copyright 2003 by Jayesh Jain
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid