Springboot调用webservice,避免命名空间不匹配
·
Springboot调用webservice,不需要指定命名空间,避免命名空间不匹配
使用cxf来调用webservice
导入maven依赖
集成cxf
<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-spring-boot-starter-jaxws -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>4.0.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-transports-http -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>4.0.4</version>
</dependency>
调用webService
CXF自带的JaxWsDynamicClientFactory可以通过反射获取到Client对象,通过Client对象执行webService中的方法
public static void main(String[] args) throws Exception {
//生成代理工厂,代理工厂调用无需指定命名空间
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
//配置调用地址
Client client = clientFactory.createClient("http://www.xxx.com/services/TestService?wsdl");
//配置调用方法和参数
Object[] result = client.invoke("getInfo", "参数1","参数2",0);
//打印调用结果
System.out.println(result[0]);
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)