Use VB. NET to implement Google Web Service

Source: Internet
Author: User
Web service is one of the most important development technologies in the Internet world today. We can use XML (Extensible Markup Language), Soap (Simple Object Access Protocol), and WSDL (Web Services Description Language) and UDDI (unified description, discovery, and integration protocols) use the Web Service technology in a standard way to connect business applications and clients.

XML can be used to construct data, soap can be used for data transmission, WSDL can be used to describe services, and UDDI can be used to obtain a list of available services. Web service allows applications to communicate with each other without considering hardware systems, operating systems, and programming languages.

The difference between a web service and a previous model is that it does not provide user interfaces. On the contrary, a Web Service exposes programmable business logic. Therefore, you can add your own interfaces to the application as needed.

In this article, we will learn how to use Microsoft Visual Basic. Net to implement Google Web service.

Google Web Service

Google is a very important web site that provides the public with Web services that allow applications to use functions such as search and spelling checks. Now let's take a look at how to use this service in applications through Visual Basic. net.

Before accessing Google Web service, we need to create a Google account and obtain a license key. Only in this way can we perform about 1000 automatic queries in a day.

When creating a Google account, visit http://www.google.co.nz/apis /. Once you have entered your email address and password, Google will send your license key to your mailbox via email. We will use the license key in this example.

Start from here

Now we have obtained the required license key. Next we will go to Visual Basic.. Net to create a custom search and spell checker by using Google's Web Service API (Application Programming Interface.

Open Visual Studio. NET and create a new windows application project. Name this project googleapi and click OK:

Add web reference pointing to Google Web Service

Next, we need to add a web reference pointing to Google Web Service (this is very similar to adding a reference pointing to a COM/ActiveX object, but after adding a web reference, we have the right to access the XML Web Service on the Google server ).

Open your Solution Explorer, right-click references, and click Add web reference. Alternatively, you can select the project menu and click Add web reference.

In the address bar, type A http://api.Google.com/GoogleSearch.wsdl (Note: Make sure that the content you typed is correct, that is, exactly the same as it is displayed, especially note that the URL is case sensitive ):

After you enter the URL address and press the Enter key, Google Web service will be imported. The screen you see should be similar to the window shown in the preceding example. Finally, click Add reference to add this web reference to our project.

Execute Google Web Service

Click web reference in the solution browser window to view the Google Web reference we have added before. We rename it Google by right-clicking the reference and clicking rename:

Create a user interface, as shown in. Add the following controls:

A) used for search:

Txtsearch-text box

Lbl_totalfound-tag

Btn_search-button

B) used for spelling check:

Txt_checkspelling-text box

Lbl_correctspelling-tag

Btn_checkspelling button

Enter 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
     

Enter the following code into the Click Event of the spelling check 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 completed the coding of the application, you can run the application, type a text in the search box, and click the Google search button to view the number of results. We can also test and verify Google spelling checks.

Our web service achieves the expected goal and runs properly. Our implementation is just a few lines of code!

Conclusion

This article describes in detail how to integrate a web service into an application. You can handle this access as follows:

· Publish regular subscription search requests to monitor new Web information about a subject.

· Conduct market research by analyzing the available information amount of different topics.

· Search through non-HTML interfaces, such as command lines, papers, or visual applications.

· Carry out innovation activities to make full use of information on the Web.

· Add Google spelling check to the application.

The search syntax supported by Google Web Service is the same as that supported by Google .com. At the same time, it provides up to 1,000 queries per day for developers registered with Google Web Service (This number is sufficient for small/medium-sized applications)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.