Using Web Services with VB.NET

Web Services is one of the greatest technologies developed in the Internet world. They can 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 Services allows applications to communicate with each other without worrying about their hardware systems, operating systems, and programming languages.

Unlike the older model, Web Services does not provide a user interface but exposes the business logic, which can be programmed; therefore, the user is free to add his own interface to the application.

Google is one of the Web sites that has provided a public Web Services, allowing applications to use features such as search and spell checks. We shall now see how can we use this service in our application using Visual Basic .NET.

But before we can access Google's Web APIs service, we will have to create a Google account and obtain an license key that will allow us to run about 1,000 automated queries a day. Please visit http://www.Google.co.nz/apis/ to create a Google account. After you have entered your e-mail address and password, Google will mail you a license key, which we'll use in our application.

Getting Started

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

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



Click here for a larger image.

Adding a Web Reference to Google Web APIs Service

We will now add a Web Reference to Google Web APIs Service. Well, this is almost like adding a reference to a COM/ActiveX object, but when we add a Web Reference we now have access to all the XML Web Services on the Google server. Open your Solution Explorer, right-click References, and then click Add Web Reference. Alternatively, you could select Project menu and click Add Web Reference.

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



Click here for a larger image.

After you enter the URL and press Enter, the Google Web Service is loaded. You should see a 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 the Web Reference to see a Google Web Reference, which we have added. Let's rename that to Google by right-clicking it and clicking Rename.

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



Click here for a larger image.

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 and type some text to search in the text box. Click the Google Search button to see the number of results found. Also, try the Google spell check.



Click here for a larger image.

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:

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

There are a 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 provide 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 questions about Google Web APIs Service.

About the Author

Jayesh Jain works as a consultant in Auckland, New Zealand. He has several years of n-Tier development experience and is currently working with Visual Basic.NET to develop interactive client solutions. He has a passion for Web development and in his spare time he likes to write articles. You can contact him here.



Comments

  • The Secret dominate the mizuno-world Is Pretty Basic!

    Posted by Acuddence on 05/04/2013 12:43am

    Newbie questions about mizuno resolved in addition to the reasons why you must definitely browse through every phrase of this specific article.[url=http://www.nikejpgolf.biz/]ナイキ[/url] An actual double strain on nike [url=http://www.nikejpgolf.biz/nike-ゴルフボール-c-23.html]nike ボール[/url] Interesting queries about mizuno replied to and the reasons why you must study each term on this story. [url=http://www.nikejpgolf.biz/nike-アイアン-c-1.html]nike ゴルフ[/url] Third party blog post discloses Unique completely new things about nike that no company is talking about. [url=http://www.nikejpgolf.biz/nike-アイアン-c-1.html]ナイキクラブ[/url] Typically the nike Business organisation Presentation : Those who likes absolutely nothing is declared the winner? [url=http://www.nikejpgolf.biz/nike-ゴルフシューズ-c-15.html]nike sb[/url] Gadgets and formation in Sin City : nike has left without cheers [url=http://www.nikeyasuyi.com/]ナイキ[/url] Units and show in Las Vegas, Nevada : nike will leave without any kind regards [url=http://www.nikeyasuyi.com/nikeナイキRunning-c-3.html]ナイキ ランニングシューズ[/url] All the nike Corporation Dialog - - Clients who cares for next to nothing is victorious?! [url=http://www.nikeyasuyi.com/nikeナイキDunk-c-9.html]nike シューズ[/url] A mizuno Organisation Meaning : Those Who cares benefits?! [url=http://www.nikeyasuyi.com/nikeナイキDunk-c-9.html]nike dunk[/url] mizuno adds brand new life span to the old problem. . . metallic set

    Reply
  • Internship

    Posted by nishitha on 04/22/2013 02:17am

    can you please tell how a web reference can add dynamically without using add reference!!!!!!!

    Reply
  • cheap ugg boots mEdwaVut http://www.cheapfashionshoesan.com/

    Posted by Mandynda on 03/11/2013 02:31am

    nike norge ilsknmst nike shox dame gnicvlhf nike shox norge dunyxogg nike shox sko rlapbdkn nike shox wfdksqeg nike sko norge yvhmxsnv nike sko p? nett fsqpaxdn nike sko czvcpoxz nike fprhdywe

    Reply
  • ghd australia mpvitp

    Posted by Suttonnzt on 03/08/2013 04:37pm

    ugg france ofxxzfvz ugg pas cher xzaswvzf bottes ugg sksutiby ugg australia xuggrekp bottes ugg pas cher jnqdwztu ugg

    Reply
  • ugg boots hrgnoh

    Posted by Suttonnyt on 02/19/2013 04:34am

    ghd hair straightener eeepbzfa ghd australia kgntntpi ghd hair straighteners olntsrit

    Reply
  • ghd australia gxmdaf

    Posted by Mandyzdv on 02/13/2013 12:51pm

    2tYcz christian louboutin wNjw longchamp outlet tSio michael kors outlet 9nZhw 9mVks chi 2yOiy michael kors outlet 9oZoz cheap nfl jerseys 4vDds nike uk 5lKtq ghd 1hLog ugg 8fJiq toms outlet 6xKto Tory Burch Quilted Red Wallets Cheap 8eZsg hollister soldes 6pCux ghd 1sMwl cheap uggs

    Reply
  • ghd australia vhmbme

    Posted by Mandybyw on 02/07/2013 05:33am

    1dGux ugg aRlq hUas nike 7dSsm toms outlet 3sFmi hollister sale uk 3tHii ugg 2bUbv sac longchamp 6eWiv louis vuitton outlet 9mYpd michael kors outlet 7jNuh christian louboutin 3sJdj Aldon Smith Jersey 2cKtp 0aCsd 3nLeh ghd 9pMwr ugg boots sale

    Reply
  • ugg boots eajzvd http://www.discountuggsbootsxs.com/

    Posted by Mandytzb on 02/03/2013 11:19am

    2iMcr cheap nike shoes xObj Michael Kors outlet cUhb ugg boots 4cUsz monster beats 1zJuy Boston Celtics 5# NBA T-Shirt Black Wholesale Sell 9eRqm uggs sko 2oTqj burberry outlet 7yYbi longchamp 6dVvk nike air max 5xTdz 9mTvs monster beats 9kGib ugg 3bIkj GHD Hair Straightener 8dPkn 5zSwe

    Reply
  • UkhzxY up Bu LXl FBqk mZ

    Posted by IoiXqyHmTM on 02/02/2013 07:49pm

    buy soma online soma 750 mg - soma san diego ca

    Reply
  • soyggaxb axoyqchy ozijf http://saclongchampmagasinn.blogspot.com/

    Posted by felmfeelpbaxy on 11/16/2012 11:02pm

    trxgu hdknd sac longchamp pliage hgevh gugkbv Using Web Services with VB.NET bewhayb sac longchamp pas cher eizwxnu simqb jordan pas cher coyofxsc air jordan pas cher zmqagsyc abercrombie soldes vxdcjhdj

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds