




已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
Java調(diào)用.net寫的webservice2Java使用axis來調(diào)用.net寫的asmx WebService,大體步驟如下。Axis需要用到的包如下:1. axis.jar2. commons-discovery-0.2.jar3. commons-logging-1.0.4.jar4. jaxrpc.jar5. wsdl4j-1.5.1.jarjava調(diào)用的代碼如下:.net webService的GetSafeMode方法 WebMethod public string GetSafeMode(string factoryId, string simId) . return “0”; 上面的例子演示了怎樣傳遞參數(shù)和接收返回值,傳遞string類型的數(shù)據(jù)。下面看看怎么解決傳遞Dataset的問題。(以下為轉(zhuǎn)貼)原文地址:/blog/325610版權(quán)歸原文作者所有package etpsmsws.etpsms.hnas; import java.util.Iterator; import space.QName; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.message.MessageElement; import org.apache.axis.types.Schema; /* * * Title: * * * Description: * * * Copyright: Copyright (c) 2004 * * * Company: * * * author not attributable * version 1.0 */ public class testSoap2 public testSoap2() public static void main(String args) try String wsdlUrl = http:/test; String soapActionURI = HNAS.EtpSms.EtpSmsWS/GetRecvFromTemp; Service service = new Service(); Call call = (Call) service.createCall(); / / call.setOperationName(new QName(HNAS.EtpSms.EtpSmsWS, / EtpSmsWSSoap); call.setOperationName(new QName(HNAS.EtpSms.EtpSmsWS, GetRecvFromTemp); call.setTargetEndpointAddress(new .URL(wsdlUrl); call.addParameter(new QName(HNAS.EtpSms.EtpSmsWS, iMemberId), org.apache.axis.encoding.XMLType.XSD_INT, javax.xml.rpc.ParameterMode.IN); call.setReturnType(org.apache.axis.encoding.XMLType.XSD_SCHEMA); call.setUseSOAPAction(true); call.setSOAPActionURI(soapActionURI); Object objs = new Object 8918; Object res = call.invoke(objs); / System.out.println(res); Schema schema = (Schema) res; MessageElement messageElement = schema.get_any(); for (int i = 0; i messageElement.length; i+) / System.out.println(messageElementi.getChildElements(); / System.out.println(messageElementi.getRealElement() / .getChildren(); Iterator iterator = messageElementi.getChildElements(); while (iterator.hasNext() MessageElement m = (MessageElement) iterator.next(); m = m.getRealElement(); Iterator it = m.getChildElements(); while (it.hasNext() m = (MessageElement) it.next(); it = m.getChildElements(); while (it.hasNext() m = (MessageElement) it.next(); System.out.println(m.getValue(); catch (Exception ex) System.err.println(ex.toString(); 注意事項: 參數(shù)必須是String類型的,你定義的是啥類型不管。 setOperationName 要給方法名。 1. 概述 很多正在開發(fā)或者打算開發(fā)XML Web Services的程序員都問過這樣的一個問題:我的Web Service返回的結(jié)果是一個DataSet類型的對象,但如果我的客戶端不是用.NET寫的(因而沒有內(nèi)建的DataSet類型), 那該如何調(diào)用這個Web Service并訪問DataSet中的數(shù)據(jù)呢?。 對于這個問題,首先應該說的是:1)在多種語言共存的編程環(huán)境下,是不適合使用類似DataSet這種只屬于特定語言的數(shù)據(jù)類型的。不管是在 XML Web Services還是CORBA的環(huán)境中,都應該盡量使用簡單數(shù)據(jù)類型以及簡單數(shù)據(jù)類型的數(shù)組。2)應當很謹慎的決定是否需要通過Web Service來返回大量數(shù)據(jù)。由于網(wǎng)絡傳輸?shù)拈_銷既包括HTTP連接建立的時間,也包括傳送數(shù)據(jù)的時間,因此需要在減少訪問服務器次數(shù)和減少網(wǎng)絡傳輸量 之間尋找一個合適的平衡。如非必須,則不適合通過Web Service傳送含有幾十條或者幾百條數(shù)據(jù)的數(shù)據(jù)表。 然后,就問題本身而言,.NET Web Services返回的DataSet類型是可以直接被其他非.NET的客戶端解析的,因為即便是DataSet類型的返回值,也會被表達成XML格式再 進行傳輸。下面的例子就是一個返回類型為DataSet的Web Method,及其被調(diào)用后返回的XML格式數(shù)據(jù): 2. 創(chuàng)建.NET Web Services,返回數(shù)據(jù)集合 WebMethod public DataSet GetPersonTable(string str) . DataTable table = new DataTable(Person); table.Columns.Add(Name); table.Columns.Add(Gender); table.Rows.Add(new string2 . Alice, Female ); table.Rows.Add(new string2 . Bob, Male ); table.Rows.Add(new string2 . Chris, Female ); table.Rows.Add(new string2 . Dennis, Male ); table.Rows.Add(new string2 . Eric, Male ); DataSet dataset = new DataSet(PersonTable); dataset.Tables.Add(table); return dataset; 3. 在Java中調(diào)用.NET Web Services,處理返回的數(shù)據(jù)集合 try . String wsdlUrl = http:/localhost/WebSite1/Service.asmx?op=GetPersonTable; String soapActionURI = /GetPersonTable; Service service = new Service(); Call call = (Call) service.createCall(); / call.setOperationName(new QName(/,GetPersonTable); call.setTargetEndpointAddress(new .URL(wsdlUrl); call.addParameter(a, org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); call.setReturnType(org.apache.axis.encoding.XMLType.XSD_SCHEMA); call.setUseSOAPAction(true); call.setSOAPActionURI(soapActionURI); Object objs = new Object.ssss; Object res = call.invoke( objs ); System.out.println(res); Schema schema = (Schema)res; DefaultTableModel model=new DefaultTableModel(new S,gender,0); schema.get_any()1.getChildNodes().getLength(); int nLength=schema.get_any()1.getChildNodes().item(0).getChildNodes().getLength(); String name=N/A; String gender=N/A; for(int i=0;inLength;i+) . if(schema.get_any()1.getChildNodes().item(0).getChildNodes().item(i).getChildNodes().item(0).getNodeName().equals(Name) . name=schema.get_any()1.getChildNodes().item(0).getChildNodes().item(i).getChildNodes().item(0).getFirstChild().getNodeValue(); if(schema.get_any()1.getChildNodes().item(0).getChildNodes().item(i).getChildNodes().item(1).getNodeName().equals(Gender) . gender=schema.get_any()1.getChildNodes().item(0).getChildNodes().item(i).getChildNodes().item(1).getFirstChild().getNodeValue(); model.addRow(new S,gender); this.jScrollPane1.getViewport().add(jTable1, null); jTable1.setModel(model); catch (Exception ex) . System.err.println(ex.toString(); public String ValidateUser(String uId,String uPwd);需傳2個參數(shù),字符串類型的用戶名和密碼(需按順序填寫,以下同理)返回succ表明驗證通過,fail表明驗證不通過在java中調(diào)用如下:public static void main(String args) try String endpoint = 08:8080/Controls/services/UserInfo;/ip地址 Service service = new Service(); Call call = null; call = (Call) service.createCall(); call.setOperationName(new QName(endpoint, ValidateUser);/方法名 call.setTargetEndpointAddress(new .URL(endpoi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 項目技術(shù)咨詢和知識產(chǎn)權(quán)許可協(xié)議
- 新型農(nóng)業(yè)經(jīng)營主體融資租賃合同書
- 農(nóng)戶土地租賃與種植協(xié)議
- 農(nóng)業(yè)產(chǎn)業(yè)鏈優(yōu)化升級合作框架合同
- 元宵節(jié)作文怎么寫4年級7篇
- 夢想初三作文600字7篇
- 2025版化工產(chǎn)品采購合同范本
- 2025版金融行業(yè)保密協(xié)議及競業(yè)限制服務合同
- 二零二五版礦產(chǎn)資源采礦權(quán)出讓與礦業(yè)權(quán)交易合同范本
- 二零二五年度SaaS定制化企業(yè)財務管理系統(tǒng)銷售合同
- 勞務裝修包清工勞務合同
- DB11T 418-2019 電梯日常維護保養(yǎng)規(guī)則
- 高考語文備考之考場中的韓愈詩歌文言文匯編
- 學校廚房設備投標方案(技術(shù)標)
- 養(yǎng)老院護理服務質(zhì)量提升手冊
- 一例下肢靜脈血栓疑難病例護理討論
- DB37T 5281-2024 地源熱泵系統(tǒng)工程技術(shù)規(guī)程
- 物聯(lián)網(wǎng)行業(yè)技術(shù)崗位總結(jié)
- 康復心理學與心理干預
- LED照明有關(guān)國家標準及對應國際標準
- 文創(chuàng)產(chǎn)品定制合同范本
評論
0/150
提交評論