1、生成客户端代码
使用apache-cxf
直接生成客户端代码:
在http://cxf.apache.org下载最新的apache-cxf,并配置环境变量,例如下图:
使用命令窗口切换至需要生成代码的文件夹下,执行
wsdl2java http://localhost:8080/ws/cxf/findReportEntity?wsdl
(其中http://localhost:8080/ws/cxf/findReportEntity?wsdl
为服务端发布的wsdl接口描述),生成客户端代码,目录如下:
2、添加客户端依赖
依赖内容与管理端相同,这里只添加cxf必要的依赖
<!--cxf webservice need-->
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<properties>
<cxf.version>3.0.4</cxf.version>
</properties>
3、测试服务
package skytech.casedemo.ws;
import org.testng.annotations.Test;
/**
* Created by ht on 2017/1/20.
* 客户端测试代码,配合服务端使用,
* 具体的链接方式由调用wsdl生成客户端代码时写入代码
*/
@Test
public class WsClientTest {
String pkid = "2132";
public void wsClientTest() {
ReportEntityServiceImplService service = new ReportEntityServiceImplService();
ReportEntityService reportEntityService = service.getReportEntityServiceImplPort();
ReportEntity reportEntity = reportEntityService.findOne(pkid);
assert (pkid+"_测试的直报主体").equals(reportEntity.getEnterpirseName());
System.out.println(reportEntity.getEnterpirseName());
}
}