在輸入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