日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WSDL解析

發布時間:2025/7/14 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WSDL解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

背景

前面我們介紹過利用javassist動態生成webservice,這種方式可以使得我們系統通過頁面配置動態發布webservice服務,做到0代碼開發發布北向接口。進一步思考,我們如何0代碼開發調用第三方webservice服務呢?

wsdl解析

首先必然是理解第三方webservice的接口描述,也就是解析wsdl文件。wsdl文件是webservice服務接口描述文檔,一個wsdl文件可以包含多個接口,一個接口可以包含多個方法。

實際上,wsdl解析是十分困難的工作,網上也沒有找到有效的解決辦法,最終通過閱讀SoapUI源碼,找到了完美的解析方法。

代碼

1 /** 2 * WsdlInfo.java Create on 2013-5-4 下午12:56:14 3 * 4 * 類功能說明: wsdl解析入口 5 * 6 * Copyright: Copyright(c) 2013 7 * Company: COSHAHO 8 * @Version 1.0 9 * @Author 何科序 10 */ 11 public class WsdlInfo 12 { 13 private String wsdlName; 14 15 private List<InterfaceInfo> interfaces; 16 17 /** 18 * coshaho 19 * @param path wsdl地址 20 * @throws Exception 21 */ 22 public WsdlInfo(String path) throws Exception 23 { 24 WsdlProject project = new WsdlProject(); 25 WsdlInterface[] wsdlInterfaces = WsdlImporter.importWsdl( project, path ); 26 this.wsdlName = path; 27 if(null != wsdlInterfaces) 28 { 29 List<InterfaceInfo> interfaces = new ArrayList<InterfaceInfo>(); 30 for(WsdlInterface wsdlInterface : wsdlInterfaces) 31 { 32 InterfaceInfo interfaceInfo = new InterfaceInfo(wsdlInterface); 33 interfaces.add(interfaceInfo); 34 } 35 this.interfaces = interfaces; 36 } 37 } 38 39 public String getWsdlName() { 40 return wsdlName; 41 } 42 43 public void setWsdlName(String wsdlName) { 44 this.wsdlName = wsdlName; 45 } 46 47 public List<InterfaceInfo> getInterfaces() { 48 return interfaces; 49 } 50 51 public void setInterfaces(List<InterfaceInfo> interfaces) { 52 this.interfaces = interfaces; 53 } 54 } 1 /** 2 * 3 * InterfaceInfo.java Create on 2016年7月20日 下午9:03:21 4 * 5 * 類功能說明: 接口信息 6 * 7 * Copyright: Copyright(c) 2013 8 * Company: COSHAHO 9 * @Version 1.0 10 * @Author 何科序 11 */ 12 public class InterfaceInfo 13 { 14 private String interfaceName; 15 16 private List<OperationInfo> operations; 17 18 private String[] adrress; 19 20 public InterfaceInfo(WsdlInterface wsdlInterface) 21 { 22 this.interfaceName = wsdlInterface.getName(); 23 24 this.adrress = wsdlInterface.getEndpoints(); 25 26 int operationNum = wsdlInterface.getOperationCount(); 27 List<OperationInfo> operations = new ArrayList<OperationInfo>(); 28 29 for(int i = 0; i < operationNum; i++) 30 { 31 WsdlOperation operation = ( WsdlOperation )wsdlInterface.getOperationAt( i ); 32 OperationInfo operationInfo = new OperationInfo(operation); 33 operations.add(operationInfo); 34 } 35 36 this.operations = operations; 37 } 38 39 public String getInterfaceName() { 40 return interfaceName; 41 } 42 43 public void setInterfaceName(String interfaceName) { 44 this.interfaceName = interfaceName; 45 } 46 47 public List<OperationInfo> getOperations() { 48 return operations; 49 } 50 51 public void setOperations(List<OperationInfo> operations) { 52 this.operations = operations; 53 } 54 55 public String[] getAdrress() { 56 return adrress; 57 } 58 59 public void setAdrress(String[] adrress) { 60 this.adrress = adrress; 61 } 62 } 1 /** 2 * 3 * OperationInfo.java Create on 2016年7月20日 下午9:03:42 4 * 5 * 類功能說明: 方法信息 6 * 7 * Copyright: Copyright(c) 2013 8 * Company: COSHAHO 9 * @Version 1.0 10 * @Author 何科序 11 */ 12 public class OperationInfo 13 { 14 private String operationName; 15 16 private String requestXml; 17 18 private String responseXml; 19 20 public OperationInfo(WsdlOperation operation) 21 { 22 operationName = operation.getName(); 23 requestXml = operation.createRequest( true ); 24 responseXml = operation.createResponse(true); 25 } 26 27 public String getOperationName() { 28 return operationName; 29 } 30 31 public void setOperationName(String operationName) { 32 this.operationName = operationName; 33 } 34 35 public String getRequestXml() { 36 return requestXml; 37 } 38 39 public void setRequestXml(String requestXml) { 40 this.requestXml = requestXml; 41 } 42 43 public String getResponseXml() { 44 return responseXml; 45 } 46 47 public void setResponseXml(String responseXml) { 48 this.responseXml = responseXml; 49 } 50 }

測試代碼

1 package com.coshaho.integration; 2 3 import com.coshaho.integration.wsdl.InterfaceInfo; 4 import com.coshaho.integration.wsdl.OperationInfo; 5 import com.coshaho.integration.wsdl.WsdlInfo; 6 7 /** 8 * 9 * WSDLParseTest.java Create on 2016年7月20日 下午9:24:36 10 * 11 * 類功能說明: WSDL解析測試 12 * 13 * Copyright: Copyright(c) 2013 14 * Company: COSHAHO 15 * @Version 1.0 16 * @Author 何科序 17 */ 18 public class WSDLParseTest 19 { 20 public static void main(String[] args) throws Exception 21 { 22 String url = "http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx?wsdl"; 23 WsdlInfo wsdlInfo = new WsdlInfo(url); 24 System.out.println("WSDL URL is " + wsdlInfo.getWsdlName()); 25 26 for(InterfaceInfo interfaceInfo : wsdlInfo.getInterfaces()) 27 { 28 System.out.println("Interface name is " + interfaceInfo.getInterfaceName()); 29 for(String ads : interfaceInfo.getAdrress()) 30 { 31 System.out.println("Interface address is " + ads); 32 } 33 for(OperationInfo operation : interfaceInfo.getOperations()) 34 { 35 System.out.println("operation name is " + operation.getOperationName()); 36 System.out.println("operation request is "); 37 System.out.println("operation request is " + operation.getRequestXml()); 38 System.out.println("operation response is "); 39 System.out.println(operation.getResponseXml()); 40 } 41 } 42 } 43 }

測試結果

1 WSDL URL is http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx?wsdl 2 Interface name is ChinaOpenFundWSSoap12 3 Interface address is http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx 4 operation name is getFundCodeNameDataSet 5 operation request is 6 operation request is <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/"> 7 <soap:Header/> 8 <soap:Body> 9 <web:getFundCodeNameDataSet/> 10 </soap:Body> 11 </soap:Envelope> 12 operation response is 13 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 14 <soap:Header/> 15 <soap:Body> 16 <web:getFundCodeNameDataSetResponse> 17 <!--Optional:--> 18 <web:getFundCodeNameDataSetResult> 19 <xs:schema> 20 <!--Ignoring type [{http://www.w3.org/2001/XMLSchema}schema]--> 21 </xs:schema> 22 <!--You may enter ANY elements at this point--> 23 </web:getFundCodeNameDataSetResult> 24 </web:getFundCodeNameDataSetResponse> 25 </soap:Body> 26 </soap:Envelope> 27 operation name is getFundCodeNameString 28 operation request is 29 operation request is <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/"> 30 <soap:Header/> 31 <soap:Body> 32 <web:getFundCodeNameString/> 33 </soap:Body> 34 </soap:Envelope> 35 operation response is 36 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/"> 37 <soap:Header/> 38 <soap:Body> 39 <web:getFundCodeNameStringResponse> 40 <!--Optional:--> 41 <web:getFundCodeNameStringResult> 42 <!--Zero or more repetitions:--> 43 <web:string>?</web:string> 44 </web:getFundCodeNameStringResult> 45 </web:getFundCodeNameStringResponse> 46 </soap:Body> 47 </soap:Envelope> 48 operation name is getOpenFundDataSet 49 operation request is 50 operation request is <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/"> 51 <soap:Header/> 52 <soap:Body> 53 <web:getOpenFundDataSet> 54 <!--Optional:--> 55 <web:userID>?</web:userID> 56 </web:getOpenFundDataSet> 57 </soap:Body> 58 </soap:Envelope> 59 operation response is 60 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 61 <soap:Header/> 62 <soap:Body> 63 <web:getOpenFundDataSetResponse> 64 <!--Optional:--> 65 <web:getOpenFundDataSetResult> 66 <xs:schema> 67 <!--Ignoring type [{http://www.w3.org/2001/XMLSchema}schema]--> 68 </xs:schema> 69 <!--You may enter ANY elements at this point--> 70 </web:getOpenFundDataSetResult> 71 </web:getOpenFundDataSetResponse> 72 </soap:Body> 73 </soap:Envelope>

?

轉載于:https://www.cnblogs.com/coshaho/p/5689738.html

總結

以上是生活随笔為你收集整理的WSDL解析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。