IDEA生成webService服务器端客户端

IDEA生成webService服务器端

1.新建项目如图:

IDEA生成webService服务器端客户端_第1张图片

2.下一步点击finish,然后会生成一个webservice项目,在HelloWorld类里面写自己的方法,需要将为该服务发布WSDL文件,此文件必须生成,如下图:
IDEA生成webService服务器端客户端_第2张图片

3.放入Tomcat 进行运行就可以了.一个webservice服务器端就完成了.访问路径

IDEA生成webService服务器端客户端_第3张图片

4.把你的发布的服务地址发给其他人就可以了.

我的地址:http://localhost:9999/services/HelloWorld?wsdl

在项目中引用webService客户端

1.导入需要的pom

<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-web-servicesartifactId>
dependency>
<dependency>
    <groupId>org.apache.cxfgroupId>
    <artifactId>cxf-rt-frontend-jaxwsartifactId>
    <version>3.1.6version>
dependency>
<dependency>
    <groupId>org.apache.cxfgroupId>
    <artifactId>cxf-rt-transports-httpartifactId>
    <version>3.1.6version>
dependency> 

通过wsdl生成Java代码

IDEA生成webService服务器端客户端_第4张图片

IDEA生成webService服务器端客户端_第5张图片

成功执行后可以看到多了很多文件,直接调用即可

 @Test
    public void contextLoads() {
        DemoServiceImplService webServiceImpl = new DemoServiceImplService();
        String result = webServiceImpl.getDemoServiceImplPort().sayHello("没有说");
        System.out.println("===========================================");
        System.out.println(result);
        System.out.println("===========================================");
    }

你可能感兴趣的:(实战记录)