在输入url地址并按下回车键之后,google web service就会导入,您看到的屏幕应该与上面示例中所显示的窗口类似。最后,单击添加引用按钮将此web 引用添加到我们工程中。
执行google web service
请在解决方案浏览器窗口中单击web 引用,这样就可以查看我们在此之前已添加的google web 引用 。我们将其重新命名为google,具体方法是右键单击此引用并单击重新命名:
创建用户接口,如下图所示。添加下列控件:
a) 用于搜索:
txtsearch - 文本框
lbl_totalfound - 标签
btn_search - 按钮
b) 用于拼写检查:
txt_checkspelling - 文本框
lbl_correctspelling - 标签
btn_checkspelling 按钮
请将下列代码输入到google 搜索按钮(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
请将下列代码输入到拼写检查按钮(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