java webservice接口调用_WebService接口调用实战之Apache CXF

Apache CXF 是一个开源的 Web Services 框架。

如果需要轻松实现 Web Services 的发布和使用,可以将其作为其中一种解决方案。

本次技术:

        springboot

        cxf. 等

一、下载Apache CXF并配置环境变量

下载地址:http://cxf.apache.org/download.html

dd0d22d27b68847ebd51764f4bee93e6.png

下载并解压到硬盘!

配置环境变量:

CXF_HOME: 解压地址\apache-cxf-3.4.0

Path: %CXF_HOME%\bin

配置完成后,cmd校验,成功如下:

8978dad21846627f9cab91e5523a487e.png

二、根据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());        }     }}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值