圖3.2.4[2]結果時,表示成功生成。
圖3.2.4[2] 編譯結果
此時,在Eclipse左側的區域此項目的目錄如圖3.2.4[3]所示:


圖3.2.4[3] 工程目錄
至此為止,gar包生成結束,剩下的就是如何將其部署到容器中了。
3.5 部署網格服務
使用GDT插件在Eclipse下開發網格服務後,部署起來則相對簡單了不少。選中剛剛生成的gar包,右鍵Grid→Deploy(GT4 local container),如圖3.2.5[1]所示:

圖3.2.5[1] 部署過程
部署成功後,還需要驗證一下此網格服務是否已存在於容器當中並能夠查詢其相關信息了。步驟如下:
1、啟動數據庫,如圖3.2.5[2]所示。

圖3.2.5[2] 啟動數據庫
註冊數據配置信息:
2、按【win】+【r】鍵進入運行界面,輸入cmd進入DOS環境。,輸入globus-start-container –nosec,開啟容器,如圖3.2.5[3]所示。




圖3.2.5[3] 查詢結果
通過以上的驗證,已經足以證明所開發的網格服務DatabaseService已經成功部署到容器中。
3.6 開發過程中要注意的問題
1、如果包裝的是已經開發好的業務邏輯,則要把業務邏輯用到的庫文件(jar包)拷貝到工程根目錄下的lib文件夾中。這樣,在部署服務的時候這些jar文件會被自動拷貝到GT容器中的lib里,服務才能正常運行。
2、編寫服務時為變量和接口起的名字要規範,不能與某些環境保留的名字相衝突。
4 服務調用
服務調用有兩種環境,一種是在本工程的目錄下編寫客戶端進行調用,另一種就是在不同的工程目錄下甚至是在不同的操作系統環境中進行調用。
4.1 在相同的工程目錄下調用
GDT會自動為服務生成一個客戶端,但是這個客戶端可能不符合我們的需要,因此需要重新編寫客戶端,在編寫客戶端時我們可以把系統自動生成的客戶端作為參考。客戶端主要是驗證其中定義的各種操作是否可以正常使用。客戶端程序DatabaseClient.java文件內容如下:
|
public { public { try { String[] res = null; res = Selectfrommaterial(“00001”); //res = Selectfromsc(“000001001″,”Rectangle”); //res = Selectfromscandmaterial(“00001″,”000000000″,”Triangle”); if (res!=null) { for(int i=0;i<res.length;i++) System.out.println(res[i]); }else { System.out.print(“res is null!”); }; } catch(Exception e) { e.printStackTrace(); } } public DatabaseServiceAddressingLocator locator = new DatabaseServiceAddressingLocator(); String[] result = null; try{ String serviceURI = “http://127.0.0.1:8080/wsrf/services/DatabaseService”; EndpointReferenceType endpoint = new EndpointReferenceType(); endpoint.setAddress(new Address(serviceURI)); DatabasePortType data = locator.getDatabasePortTypePort(endpoint); Findexpfrommaterial f = new Findexpfrommaterial(); f.setType(type); FindexpfrommaterialResponse s =data.findexpfrommaterial(f); result = s.getFindexpfrommaterialReturn(); }catch(Exception e){ e.printStackTrace(); } return result; } public DatabaseServiceAddressingLocator locator = new DatabaseServiceAddressingLocator(); String[] result = null; try{ String serviceURI = “http://127.0.0.1:8080/wsrf/services/DatabaseService”; EndpointReferenceType endpoint = new EndpointReferenceType(); endpoint.setAddress(new Address(serviceURI)); DatabasePortType data = locator.getDatabasePortTypePort(endpoint); Findexpfromsc f = new Findexpfromsc(); f.setType(type); f.setDimension(dimension); FindexpfromscResponse s =data.findexpfromsc(f); result = s.getFindexpfromscReturn(); }catch(Exception e){ e.printStackTrace(); } return result; } public //對應於接口3的函數 DatabaseServiceAddressingLocator locator = new DatabaseServiceAddressingLocator(); String[] result = null; try{ String serviceURI = “http://127.0.0.1:8080/wsrf/services/DatabaseService”;//服務地址 EndpointReferenceType endpoint = new EndpointReferenceType();//生成端點引用 endpoint.setAddress(new Address(serviceURI)); DatabasePortType data = locator.getDatabasePortTypePort(endpoint);//根據端點引用獲得對服務的引用 Findexpfromscandmaterial f = new Findexpfromscandmaterial();//創建請求參數 f.setMaterialtype(materialtype); f.setSctype(sctype); f.setScdimension(scdimension); FindexpfromscandmaterialResponse s =data.findexpfromscandmaterial(f);//調用服務接口 result = s.getFindexpfromscandmaterialReturn(); }catch(Exception e){ e.printStackTrace(); } return result; } } |
運行客戶端程序DatabaseClient.java,在Console工作區運行結果如圖3.4所示:
圖3.4 異地調用服務結果顯示
如上圖所示,數據庫的查詢成功,則證明服務的調用成功,同時也說明網格服務DatabaseService的開發成功完成。
針對不同的服務資源模式,客戶端會有不同的編寫方法。如果服務類型為Singleton的話,則只需要獲得服務的引用然後調用接口即可;如果服務類型是Simple和Factory的話,就必須先創建資源然後再調用接口。
以下文章點擊率最高
Loading…