java_調(diào)用.net_WebService2.doc_第1頁(yè)
java_調(diào)用.net_WebService2.doc_第2頁(yè)
java_調(diào)用.net_WebService2.doc_第3頁(yè)
java_調(diào)用.net_WebService2.doc_第4頁(yè)
java_調(diào)用.net_WebService2.doc_第5頁(yè)
已閱讀5頁(yè),還剩2頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

Java調(diào)用.net寫(xiě)的webservice2Java使用axis來(lái)調(diào)用.net寫(xiě)的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類(lèi)型的數(shù)據(jù)。下面看看怎么解決傳遞Dataset的問(wèn)題。(以下為轉(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(); 注意事項(xiàng): 參數(shù)必須是String類(lèi)型的,你定義的是啥類(lèi)型不管。 setOperationName 要給方法名。 1. 概述 很多正在開(kāi)發(fā)或者打算開(kāi)發(fā)XML Web Services的程序員都問(wèn)過(guò)這樣的一個(gè)問(wèn)題:我的Web Service返回的結(jié)果是一個(gè)DataSet類(lèi)型的對(duì)象,但如果我的客戶端不是用.NET寫(xiě)的(因而沒(méi)有內(nèi)建的DataSet類(lèi)型), 那該如何調(diào)用這個(gè)Web Service并訪問(wèn)DataSet中的數(shù)據(jù)呢?。 對(duì)于這個(gè)問(wèn)題,首先應(yīng)該說(shuō)的是:1)在多種語(yǔ)言共存的編程環(huán)境下,是不適合使用類(lèi)似DataSet這種只屬于特定語(yǔ)言的數(shù)據(jù)類(lèi)型的。不管是在 XML Web Services還是CORBA的環(huán)境中,都應(yīng)該盡量使用簡(jiǎn)單數(shù)據(jù)類(lèi)型以及簡(jiǎn)單數(shù)據(jù)類(lèi)型的數(shù)組。2)應(yīng)當(dāng)很謹(jǐn)慎的決定是否需要通過(guò)Web Service來(lái)返回大量數(shù)據(jù)。由于網(wǎng)絡(luò)傳輸?shù)拈_(kāi)銷(xiāo)既包括HTTP連接建立的時(shí)間,也包括傳送數(shù)據(jù)的時(shí)間,因此需要在減少訪問(wèn)服務(wù)器次數(shù)和減少網(wǎng)絡(luò)傳輸量 之間尋找一個(gè)合適的平衡。如非必須,則不適合通過(guò)Web Service傳送含有幾十條或者幾百條數(shù)據(jù)的數(shù)據(jù)表。 然后,就問(wèn)題本身而言,.NET Web Services返回的DataSet類(lèi)型是可以直接被其他非.NET的客戶端解析的,因?yàn)榧幢闶荄ataSet類(lèi)型的返回值,也會(huì)被表達(dá)成XML格式再 進(jìn)行傳輸。下面的例子就是一個(gè)返回類(lèi)型為DataSet的Web Method,及其被調(diào)用后返回的XML格式數(shù)據(jù): 2. 創(chuàng)建.NET Web Services,返回?cái)?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個(gè)參數(shù),字符串類(lèi)型的用戶名和密碼(需按順序填寫(xiě),以下同理)返回succ表明驗(yàn)證通過(guò),fail表明驗(yàn)證不通過(guò)在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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論