Using vb.net to implement Google Web Service

Source: Internet
Author: User
Tags implement soap web services visual studio wsdl
Google|web 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), WSDL (Web Services Description Language) and UDDI (Unified description, Discovery and Integration Protocol) The Web Service technology is used in a standard way for connectivity between business applications and clients.

XML can be used to construct data, SOAP can be used for data transfer, WSDL can be used to describe a service and UDDI can be used to obtain a list of available services. Web Service makes it possible for applications to communicate with each other without regard to hardware systems, operating systems, and programming languages.

The difference between a Web service and a previous model is that it does not provide a user interface in itself, and instead the Web service exposes the programmable business logic. As a result, users can add their own interfaces to the application as needed.

In this article, we'll 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 features such as search and spell checking. Now let's take a look at how to use this service in your application through Visual Basic.NET.

Before accessing the Google Web service, we need to create a Google account and get a license key so that we can make 1000 or so automatic inquiries in one day.

When you create 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 the example in this article.

Start from here

Now that we have the required license key, we will then create an application in Visual Basic.NET to create a custom search and spelling checker by using Google's Web Service API (Application programming Interface).

Please open Visual Studio. NET and create a new Windows Application project. Name the project Googleapi and click OK:





Add a Web reference to Google Web service

Next, we need to add a Web reference to Google Web service (this is very similar to adding a reference to the Com/activex object, but after adding a Web reference, we have access to the XML Web service on the Google server).

Please open your Solution Explorer, right-click References and click Add Web Reference, or you can select the Project menu and click Add Web Reference.

In the Address bar, type HTTP://API.GOOGLE.COM/GOOGLESEARCH.WSDL Note: Make sure that you are typing correctly, exactly as shown, and that the URL is case-sensitive, especially:





After you enter the URL address and press ENTER, the Google Web service is imported, and the screen you see should resemble the window shown in the example above. Finally, click the Add Reference button to add this Web reference to our project.

Execute Google Web Service

Click the Web reference in the Solution Explorer window so that you can view the Google Web references that we have added before. We'll rename it to Google by right-clicking the reference and clicking Rename:





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

A) for search:

Txtsearch-text box

Lbl_totalfound-Tags

Btn_search-button

b) for spell checking:

txt_checkspelling-text box

Lbl_correctspelling-Tags

Btn_checkspelling button





Please 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



Please enter the following code into the click event of the 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 the application, we can then run the application and type the text in the search box, and then click the Google Search button to see the number of results found. We can also test and verify the Google spelling checker.





Our web service achieves the desired goal of working properly. And our implementation is only a few lines of code!


Conclusion


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

• Publish a periodic subscription search request to monitor the web's new information about a subject.

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

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

• Develop innovative activities to fully use information on the web.

• Add Google spell checker to your application.

The search syntax supported by Google Web service is the same as the search syntax supported by the Google.com Web site. It also provides up to 1,000 queries per day for developers who register to use Google Web service (a number that is sufficient for small/medium 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.