springboot调用webservice-soap接口的实现
作者:EntyIU
接口协议目前广泛使用的有http协议和RPC协议和webservice,本文主要介绍了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);到此这篇关于springboot调用webservice-soap接口的实现的文章就介绍到这了,更多相关springboot调用webservice-soap接口内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
