Spring Boot 使用 CXF 调用 WebService 服务
上一张我们讲到 Spring Boot 开发 WebService 服务,本章研究基于 CXF 调用 WebService。另外本来想写一篇 xfire 作为 client 端来调用 webservice 的代码。后来发现 xfire 在2007 你那巅峰时刻,已经不再更新,而后来的 Spring 已经抛弃了部分 Api。导致现在已经不兼容了。
1 新建 Spring Boot Maven 示例工程项目
注意:是用来 IDEA 开发工具
- File > New > Project,如下图选择
Spring Initializr然后点击 【Next】下一步 - 填写
GroupId(包名)、Artifact(项目名) 即可。点击 下一步
groupId=com.fishpro
artifactId=webserviceclient - 选择依赖
Spring Web Starter前面打钩。 - 项目名设置为
spring-boot-study-webserviceclient.
2 引入依赖 Pom
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 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>3.2.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
3 编写调用代码
- 实例化 JaxWsDynamicClientFactory
- 建立Client请求
- invoke方法入口,并传递参数
http://localhost:8080/ws/user?wsdl 为上一章我们编写的示例。
@SpringBootApplication
public class WebserviceclientApplication {
public static void main(String[] args) {
SpringApplication.run(WebserviceclientApplication.class, args);
JaxWsDynamicClientFactory dcflient=JaxWsDynamicClientFactory.newInstance();
Client client=dcflient.createClient("http://localhost:8080/ws/user?wsdl");
try{
Object[] objects=client.invoke("getUserById","1");
System.out.println("getUserById 调用结果:"+objects[0].toString());
Object[] objectall=client.invoke("getUsers");
System.out.println("getUsers调用部分结果:"+objectall[0].toString());
}catch (Exception e){
e.printStackTrace();
}
}
}
右键 WebserviceclientApplication 点击 Run WebserviceclientApplication
2019-08-12 18:42:42.341 INFO 63593 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8087 (http) with context path ''
2019-08-12 18:42:42.344 INFO 63593 --- [ main] c.f.w.WebserviceclientApplication : Started WebserviceclientApplication in 2.527 seconds (JVM running for 3.132)
getUserById 调用结果:com.youdomain.webservice.UserDto@3c7d8a4
getUsers调用部分结果:[com.youdomain.webservice.UserDto@4e2824b1, com.youdomain.webservice.UserDto@534d0e20, com.youdomain.webservice.UserDto@7d18338b, com.youdomain.webservice.UserDto@3f4a605f]
Spring Boot 使用 CXF 调用 WebService 服务的更多相关文章
- Spring Boot 使用 JAX-WS 调用 WebService 服务
除了 CXF 我们还可以使用 Spring Boot 自身默认的组件 JAX-WS 来实现 WebService 的调用. 本项目源码 github 下载 1 新建 Spring Boot Maven ...
- cxf 调用 webservice服务时传递 服务器验证需要的用户名密码
cxf通过wsdl2java生成客户端调用webservice时,如果服务器端需要通过用户名和密码验证,则客户端必须传递验证所必须的用户名和密码,刚开始想通过url传递用户名和密码,于是在wsdl文件 ...
- apache cxf笔记之Spring客户端访问和调用webservice服务
继续上次的spring服务的问题,这边介绍一种spring配置客户端的方法. 1.src目录下新建client-beans.xml文件 <?xml version="1.0" ...
- Spring boot 整合CXF webservice 遇到的问题及解决
将WebService的WSDL生成的代码的命令: wsimport -p com -s . com http://localhost:8080/service/user?wsdl Spring bo ...
- CXF发布webService服务以及客户端调用
这篇随笔内容是CXF发布webService服务以及客户端调用的方法 CXF是什么? 开发工作之前需要下载CXF和安装 下载地址:http://cxf.apache.org 安装过程: <1&g ...
- spring boot / cloud (十四) 微服务间远程服务调用的认证和鉴权的思考和设计,以及restFul风格的url匹配拦截方法
spring boot / cloud (十四) 微服务间远程服务调用的认证和鉴权的思考和设计,以及restFul风格的url匹配拦截方法 前言 本篇接着<spring boot / cloud ...
- SpringBoot | 第三十四章:CXF构建WebService服务
前言 上一章节,讲解了如何使用Spring-WS构建WebService服务.其实,创建WebService的方式有很多的,今天来看看如何使用apache cxf来构建及调用WebService服务. ...
- 使用apache cxf实现webservice服务
1.在idea中使用maven新建web工程并引入spring mvc,具体可以参考https://www.cnblogs.com/laoxia/p/9311442.html; 2.在工程POM文件中 ...
- 【转】构建基于CXF的WebService服务
构建基于CXF的WebService服务 Apache CXF = Celtix+ XFire,开始叫 Apache CeltiXfire,后来更名为 Apache CXF 了,以下简称为 CXF.C ...
随机推荐
- CentOS之service iptables stop 显示not loaded
停止firewalld服务停止防火墙,并禁用这个服务 sudo systemctl stop firewalld.servicesudo systemctl disable firewalld.ser ...
- Educational Codeforces Round 76 D
这次的ABC三道题非常水,但是我就卡在这个D题上了QAQ 当时大概猜到了贪心,但是没有思路,后来看了一些题解才明白到底是什么意思 首先,假设我们已经处理好了前面的monsters,对于第i个monst ...
- 大白话Web三大组件之一Servlet
很多学习到Servlet这里的童鞋,听到那么多专业名词解释这个Servlet,相信都是很蒙圈的,在这里我先不跟大家扯Servlet的大概念,先跟大家探讨一下关于Servlet的作用 相信MVC这个概念 ...
- NPOI 导出Excel表报错
当导出2007格式的时候,打开文件总是报错“发现 xxx中的部分内容有问题.是否让我们尽量尝试恢复?”. 导出的程序: protected void btnValidateInternalData_C ...
- jquery动画系统
1.隐藏显示的方法: $(selector).show(speed,callback); $(selector).hide(1000); $(selector).toggle("slow&q ...
- AcWing 837. 连通块中点的数量
#include <iostream> using namespace std; ; int n, m; int p[N], size[N]; int find(int x) { if ( ...
- 主席树板子 p2104
#include<cstdio> #include<algorithm> #include<vector> using namespace std; ; int n ...
- bodyParser.urlencoded({ })里extended: true和false区别???
- Linux - Shell - 字符串拼接
概述 shell 的字符串拼接 1. 字符串声明 概述 字符串的基本操作 脚本 1 # 声明字符串 str01="str01" echo ${str01} # 单引号也可以 # 不 ...
- 【音乐欣赏】《Wrong》 - Far Out / Emilia Ali
曲名:Wrong 作者:Far Out / Emilia Ali [00:16.03]Ride body on mine [00:18.07]Griping your waist as I was o ...