springboot项目如何调用webservice-soap接口

首先基于soap协议的传输的话,是基于类似于xml这样的wsdl格式进行传输的

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
            <version>3.3.4</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.validation</groupId>
                    <artifactId>validation-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

如果是springboot项目一定要把里边的这几个依赖排除掉,否则因为已经引入过对应的依赖了,在启动的时候会发生冲突

下边介绍两种方式:

一,首先是基于cxf的动态代理的方式

 JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient(wsdl接口路径);
        Object[] objects = client.invoke("方法名称",方法参数);

       objects[0]就是这个方法的返回值

//这里注意,如果是传递是一个对象的话,一定要注意传递的类的全路径一定要和服务端的类全路径一致,否则,会出现接受错误

二,通过java的wsimport生成客户端代码的方式,命令如下

wsimport  -s  客户端代码生成全路径   -p  代码的包路径   请求接口地址

 然后就可以通过下边这种调用方法这样的方式直接拿到调用的返回值

 AlarmHandleService alarmHandleService=new AlarmHandleService();
        AlarmHandleServiceSoap alarmHandleServiceSoap = alarmHandleService.getAlarmHandleServiceSoap();
        ReturnMessage returnMessage = alarmHandleServiceSoap.alarmSend(alarmSendMessage);

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EntyIU

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值