Apache CXF 是一个开源的 Web Services 框架。
如果需要轻松实现 Web Services 的发布和使用,可以将其作为其中一种解决方案。
本次技术:
springboot
cxf. 等
一、下载Apache CXF并配置环境变量
下载地址:http://cxf.apache.org/download.html
下载并解压到硬盘!
配置环境变量:
CXF_HOME: 解压地址\apache-cxf-3.4.0
Path: %CXF_HOME%\bin
配置完成后,cmd校验,成功如下:
二、根据wsdl文件生成客户端代码
生成命令:
wsdl2java -encoding utf-8 -impl -p 包名 -d 代码生成地址 -client wsdl文件地址
把生成的代码复制到项目中,最后一个type代码中有调用示例!
三、springboot pom.xml
<dependency> <groupId>org.apache.cxfgroupId> <artifactId>cxf-spring-boot-starter-jaxwsartifactId> <version>3.4.0version> dependency> <dependency> <groupId>org.apache.cxfgroupId> <artifactId>cxf-rt-transports-httpartifactId> <version>3.4.0version> dependency>
四、调用实例
public static void main(String args[]) throws Exception { URL wsdlURL = WebService2020.WSDL_LOCATION; if (args.length > 0 && args[0] != null && !"".equals(args[0])) { File wsdlFile = new File(args[0]); try { if (wsdlFile.exists()) { wsdlURL = wsdlFile.toURI().toURL(); } else { wsdlURL = new URL(args[0]); } } catch (MalformedURLException e) { e.printStackTrace(); } } WebService2020 ss = new WebService2020(wsdlURL, SERVICE_NAME); WebService2020PortType port = ss.getWebService2020HttpPort(); { System.out.println("Invoking xxxx..."); String _xxxx_in0 = ""; try { String _xxxx__return = port.xxxxWebservice(_xxxx_in0); System.out.println("xxxx.result=" + _xxxx__return); } catch (ParseException_Exception e) { System.out.println("Expected exception: ParseException has occurred."); System.out.println(e.toString()); } catch (DocumentException_Exception e) { System.out.println("Expected exception: DocumentException has occurred."); System.out.println(e.toString()); } }}