国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

使用VB.NET實現 Google Web Service

2024-07-10 13:01:15
字體:
來源:轉載
供稿:網友
web service 是當今因特網世界中最重要的開發技術之一,我們可通過使用xml (可擴展標記語言)、 soap (簡單對象訪問協議)、wsdl (web services 描述語言)和uddi (統一描述、發現和集成協議)以標準方式將web service技術用于業務應用和客戶端之間的連接。

xml可用于構造數據、soap 可用于數據傳輸、wsdl 可用于描述服務而uddi 可用于獲取可用服務的列表。web service 使得應用程序無須考慮硬件系統、操作系統和編程語言就可以進行相互通信。

web service與以前的模型不同之處就在于它本身并不提供用戶接口,相反web service公開揭示了可編程的業務邏輯。因此,用戶可根據需要將自己的接口添加到應用程序中。

本文中,我們將會學習如何使用 microsoft visual basic.net來實現google web service。


google web service


google是一個很重要的web站點,它向公眾提供web服務,允許應用程序使用如搜索和拼寫檢查之類的功能。現在,我們來看一看如何通過visual basic.net在應用程序中使用此服務。

在訪問google web service之前,我們需要創建一個google帳戶并獲得一個許可密鑰,只有這樣,我們才能在一天中進行1000 個左右的自動查詢。

創建google 帳戶時請訪問http://www.google.co.nz/apis/。一旦輸入了電子郵件地址和口令,google 就會通過email 將您的許可密鑰發送到您的信箱中。我們會在本文的示例中使用許可密鑰。

從這里開始

現在我們已經獲得了所需的許可密鑰,接下來我們將在visual basic.net中創建一個應用程序,以便通過使用google的web service api(應用程序編程接口)來創建自定義的搜索和拼寫檢查器。

請打開 visual studio .net ,然后創建一個新的windows 應用程序工程。將此工程命名為googleapi 并單擊確定:





添加指向google web service的web引用

下一步,我們需要添加指向google web service的web引用(這與添加指向 com/activex 對象的引用非常相似,但是添加web引用后,我們就有權訪問google 服務器上的xml web service)。

請打開您的solution explorer,右鍵單擊references并單擊添加web reference,或者您可以選擇工程菜單然后單擊add web reference。

在地址欄中,請鍵入http://api.google.com/googlesearch.wsdl (注意:請確保你所鍵入的內容正確無誤,即與所顯示的完全一樣,尤其要注意該 url是區分大小寫的):





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



現在我們已完成了應用程序的編碼工作,接下來就可以運行應用程序并在搜索框中鍵入文本,然后單擊google 搜索按鈕查看所找到的結果的數目。我們還可以對google拼寫檢查進行測試和驗證。





我們的web service 實現了預期的目標,可正常運轉。而我們的實現卻僅僅寥寥幾行代碼而已!


結論


本文詳細描述了如何將web service 集成到應用程序中。您可以對此訪問進行如下處理:

·發布定期訂閱的搜索請求以監控web 有關某一主體的新信息。

·進行市場調查,方法是分析不同主題可用信息量的差別。

·通過非html 接口進行搜索,如命令行、論文或者可視化應用程序。

·開展創新活動來充分使用 web 上的信息。

·將 google 拼寫檢查添加到應用程序。

google web service 支持的搜索語法與 google.com web 站點所支持的搜索語法相同。同時它為注冊使用 google web service 的開發用戶每天提供最多1,000 次查詢(這個數目對于小型/中型應用程序來說已經足夠使用了)

最大的網站源碼資源下載站,

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 马鞍山市| 团风县| 东乡县| 乌兰县| 祁东县| 蕉岭县| 久治县| 大关县| 富锦市| 安顺市| 迭部县| 定兴县| 梨树县| 泰安市| 兴城市| 商城县| 锡林浩特市| 南江县| 商丘市| 宣威市| 涟水县| 称多县| 庆安县| 上虞市| 凭祥市| 石泉县| 乌海市| 青浦区| 新乐市| 无极县| 沾益县| 监利县| 德惠市| 两当县| 兴文县| 满洲里市| 兴业县| 通许县| 陆河县| 无棣县| 项城市|