導航:首頁 > 編程語言 > webservice客戶端代碼

webservice客戶端代碼

發布時間:2023-07-25 08:16:36

⑴ webservice中怎樣用java寫客戶端程序()

基於AXIS的web service:

1 比如要建一個Server.java類的web service
public class Server {
public String printInfo(String name){
return "Hello,"+name;
}
}
2 把Server.java改為Server.Jws放到
…\Tomcat 5.5\webapps\axis中,重啟伺服器

3 訪問http://localhost:8080/axis/Server.jws?wsdl

4 在cmd中輸入 cd D:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF
輸入命令:Java -Djava.ext.dirs=lib org.apache.axis.wsdl.WSDL2Java http://localhost:8080/axis/Server.jws?wsdl

5 找到…\Tomcat 5.5\webapps\axis\WEB-INF下生成的localhost文件夾復制到工程中

6 建一個Client端的類進行測試:
public class Client {
public static void main(String arg[]) throws ServiceException, RemoteException{
ServerService ss=new ServerServiceLocator();
Server s=ss.getServer();
System.out.println("............"+s.printInfo("shiyou"));
}
}

⑵ Java客戶端調用Webservice介面求代碼

客戶端獲得自定義對象包路徑必須和伺服器端相同,當然在客戶端也可以不用建該對象,可以將客戶端的自定義對象打成jar包,然後在客戶端引用。

猜想用反射也可以實現改對象,但目前沒有寫相關例子。

<p>importjava.io.Serializable;</p><p>{
/**
*客戶端必須有與伺服器端相同的自定義對象
*/
=1L;
privateStringid;
privateStringname;
publicStringgetId(){
returnid;
}
publicvoidsetId(Stringid){
this.id=id;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}

}</p>
[java]viewplain
packageclient;

importpo.Hello;

{
/*
[java]viewplain
*該方法名必須和服務介面一致
[java]viewplain
*/
[java]viewplain
publicHelloexample();
[java]viewplain
<preclass="java"name="code">packageclient;

importjava.net.MalformedURLException;//importjava.net.URL;

//importorg.codehaus.xfire.client.Client;
importorg.codehaus.xfire.client.XFireProxyFactory;
importorg.codehaus.xfire.service.Service;
importorg.codehaus.xfire.service.binding.ObjectServiceFactory;

importpo.Hello;

publicclassServicesClient{
publicstaticvoidmain(String[]arg)throwsMalformedURLException,
Exception{
Stringxml="http://localhost:8080/web/services/HeloWebService";
=newObjectServiceFactory();
ServiceserviceModel=objectServiceFactory
.create(IClientHelloManager.class);
=newXFireProxyFactory();
IClientHelloManagerservice=(IClientHelloManager)xFireProxyFactory
.create(serviceModel,xml);
HellolHello=service.example();
System.out.println(lHello.getId());
System.out.println(lHello.getName());
//Clientclient=newClient(newURL(
//"http://localhost:8080/web/services/HeloWebService?wsdl"));
//Object[]rsult=client.invoke("example",newObject[]{"hello"});
//Hellohello=(Hello)rsult[0];
//System.out.println();
}
}</pre>
<pre></pre>
<pre></pre>
<pre></pre>

⑶ java webservice生成的客戶端代碼 需要哪些jar包

1、安裝環境 J2SE SDK 1.4,Tomcat 5.0,eclipse 3.2。
2、下載Axis安裝包。
3、將Axis相關包文件放在回WEB-INF\lib目錄下。
4、Axis可選答的包:activation.jar; mail.jar; xmlsec-1.4.Beta1.jar拷貝到WEB-INF目錄下,生成客戶端時候需要使用。
Axis支持三種web service的部署和開發,分別為:
1、Dynamic Invocation Interface (DII)
2、Dynamic Proxy方式
3、Stubs方式
建議我們使用Stubs方式,因此我就主要就介紹一下第三種方式。
注意,Java源代碼是放在D:\workspace\test\目錄下,Axis相關包文件放在D:\workspace\test\WEB-INF目錄下。

閱讀全文

與webservice客戶端代碼相關的資料

熱點內容
java穩定排序 瀏覽:53
oppo文件管理的圖片 瀏覽:335
plc編程步數怎麼計算 瀏覽:142
ipad看電腦文件 瀏覽:935
成都製作pdf文件 瀏覽:735
怎麼樣點開電腦裡面的網路連接 瀏覽:755
微信怎麼退出賬號 瀏覽:32
w微信開發者工具 瀏覽:325
資料庫還原附加 瀏覽:713
打包成exe執行文件 瀏覽:652
信豐營銷app有哪些 瀏覽:463
蘋果文件下載項如何下載 瀏覽:179
ps摳婚紗教程 瀏覽:203
如何在移動硬碟上隱藏文件夾 瀏覽:451
瑞虎8老車機怎麼刷app 瀏覽:992
學ui設計要學java嗎 瀏覽:275
淘寶票房數據源怎麼調整 瀏覽:470
iphone5s升級ios卡黑屏 瀏覽:622
u盤沒用的文件刪不了怎麼辦 瀏覽:561
文件夾解鎖工具 瀏覽:528

友情鏈接