目录

1 背景

2 sping里头搭建webservice

2.1 wsapplication

 2.2 futurwebservice

2.3 futurewebserviceimpl

2.4 webserviceconfig

3 soapui

4 调试

4.1 启动项目

4.2 查看wsdl

4.3 soapui模拟请求ws服务

5 焕然醒悟


1 背景

最近收到一个需求,比较坑,但是大概的意思看懂了,但是其中让我大意的是:

需求说,双方通信采用报文的形式,如下:

<soap:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.ws.future.com/">
   <soap:Header/>
   <soap:Body>
      报文密文
   </soap:Body>
</soap:Envelope>

乍一看,soap呀,那这个不就是一个webservice服务嘛?于是脑子一热,就开始搭建werbservice服务了(公司里头的项目采用的是sprngmvc)

(备注:后面在模拟调试过程中发现问题:这不是一个webservice服务,就只是一个普通的rest服务,但是为了还原那会的想法,因此下面的博客将错就错。)

2 sping里头搭建webservice

公司没有使用springboot快速框架,而是采用ssm。但是spring4.x以上的版本,基本上很多springboot上的编程习惯都可以直接迁移到ssm,因此在家里复现过程,我采用了springboot基础框架。

首先使用idea快速创建一个springboot项目。

创建过程没有什么注意的点,因为在下面我会将项目的pom贴出来:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.future</groupId>
    <artifactId>ws</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>ws</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
            <version>3.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.2.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

上面这个pom这边要特别强调:

springboot的版本和cxf的版本有比较严格的要求。

我使用的cxf是3.x版本,而springboot是2.1.1版本,

一开始,我cxf是3.x版本,但是springboot采用的是最新的2.6.7版本,启动项目瞬间就是一堆的错误。

然后,就如下创建一个webservice服务:

有涉及的文件,都在上面了,下面我一个文件一个文件的解释 :

2.1 wsapplication

因为webservice服务依赖cxfservlet,因此需要打开servlet描述:

 2.2 futurwebservice

定义一个webservice接口:

package com.future.ws.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface FutureWebService {

    @WebMethod
    String wsIn();
}

2.3 futurewebserviceimpl

实现webservice接口:

package com.future.ws.ws.impl;

import com.future.ws.ws.FutureWebService;
import org.springframework.stereotype.Component;

import javax.jws.WebService;

@Component
@WebService(endpointInterface = "com.future.ws.ws.FutureWebService")
public class FutureWebServiceImpl implements FutureWebService {

    @Override
    public String wsIn(String name) {
        return "111";
    }

}

2.4 webserviceconfig

还需要针对webservice做一些配置。

package com.future.ws.config;

import com.future.ws.ws.FutureWebService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

@Configuration
public class WebServiceConfig {

    /**
     * 需要对外暴露的服务类
     */
    @Autowired
    private FutureWebService futureWebService;

    /**
     * Apache CXF 核心架构是以BUS为核心,整合其他组件。
     * Bus是CXF的主干, 为共享资源提供一个可配置的场所,作用类似于Spring的ApplicationContext,这些共享资源包括
     * WSDl管理器、绑定工厂等。通过对BUS进行扩展,可以方便地容纳自己的资源,或者替换现有的资源。默认Bus实现基于Spring架构,
     * 通过依赖注入,在运行时将组件串联起来。BusFactory负责Bus的创建。默认的BusFactory是SpringBusFactory,对应于默认
     * 的Bus实现。在构造过程中,SpringBusFactory会搜索META-INF/cxf(包含在 CXF 的jar中)下的所有bean配置文件。
     * 根据这些配置文件构建一个ApplicationContext。开发者也可以提供自己的配置文件来定制Bus。
     */
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    /**
     * 此方法作用是改变项目中服务名的前缀名,此处127.0.0.1或者localhost不能访问时,请使用ipconfig查看本机ip来访问
     * 此方法被注释后, 即不改变前缀名(默认是services), wsdl访问地址为 http://127.0.0.1:8080/services/ws/api?wsdl
     * 去掉注释后wsdl访问地址为:http://127.0.0.1:8080/soap/ws/api?wsdl
     * http://127.0.0.1:8080/soap/列出服务列表 或 http://127.0.0.1:8080/soap/ws/api?wsdl 查看实际的服务
     * 新建Servlet记得需要在启动类添加注解:@ServletComponentScan
     * <p>
     * 如果启动时出现错误:not loaded because DispatcherServlet Registration found non dispatcher servlet dispatcherServlet
     * 可能是springboot与cfx版本不兼容。
     * 同时在spring boot2.0.6之后的版本与xcf集成,不需要在定义以下方法,直接在application.properties配置文件中添加:
     * cxf.path=/service(默认是services)
     */
//    @Bean
//    public ServletRegistrationBean dispatcherServlet() {
//        return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
//    }
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), futureWebService);
        endpoint.publish("/ws/api");
        return endpoint;
    }
}

3 soapui

webservice服务调试,一般采用soapui来调试,虽然同事说可以采用postman,但是因为个人没用过,因此还是先按照经验走吧。下载地址如下:

Download REST & SOAP Automated API Testing Tool | Open Source | SoapUIhttps://www.soapui.org/downloads/soapui/

 下载下来后直接傻瓜式安装即可。

4 调试

4.1 启动项目

直接启动springboot项目:

"C:\Program Files\Java\jdk1.8.0_144\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:8906,suspend=y,server=n -Dspring.output.ansi.enabled=always -javaagent:C:\Users\32631\.IntelliJIdea2018.3\system\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_144\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\rt.jar;C:\me\future-learning\ws\target\classes;C:\maven\repository\org\springframework\boot\spring-boot-starter-web\2.1.1.RELEASE\spring-boot-starter-web-2.1.1.RELEASE.jar;C:\maven\repository\org\springframework\boot\spring-boot-starter\2.1.1.RELEASE\spring-boot-starter-2.1.1.RELEASE.jar;C:\maven\repository\org\springframework\boot\spring-boot\2.1.1.RELEASE\spring-boot-2.1.1.RELEASE.jar;C:\maven\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.1.RELEASE\spring-boot-autoconfigure-2.1.1.RELEASE.jar;C:\maven\repository\org\springframework\boot\spring-boot-starter-logging\2.1.1.RELEASE\spring-boot-starter-logging-2.1.1.RELEASE.jar;C:\maven\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\maven\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\maven\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.1\log4j-to-slf4j-2.11.1.jar;C:\maven\repository\org\apache\logging\log4j\log4j-api\2.11.1\log4j-api-2.11.1.jar;C:\maven\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\maven\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\maven\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\maven\repository\org\springframework\boot\spring-boot-starter-json\2.1.1.RELEASE\spring-boot-starter-json-2.1.1.RELEASE.jar;C:\maven\repository\com\fasterxml\jackson\core\jackson-databind\2.9.7\jackson-databind-2.9.7.jar;C:\maven\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\maven\repository\com\fasterxml\jackson\core\jackson-core\2.9.7\jackson-core-2.9.7.jar;C:\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.7\jackson-datatype-jdk8-2.9.7.jar;C:\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.7\jackson-datatype-jsr310-2.9.7.jar;C:\maven\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.7\jackson-module-parameter-names-2.9.7.jar;C:\maven\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.1.RELEASE\spring-boot-starter-tomcat-2.1.1.RELEASE.jar;C:\maven\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.13\tomcat-embed-core-9.0.13.jar;C:\maven\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.13\tomcat-embed-el-9.0.13.jar;C:\maven\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.13\tomcat-embed-websocket-9.0.13.jar;C:\maven\repository\org\hibernate\validator\hibernate-validator\6.0.13.Final\hibernate-validator-6.0.13.Final.jar;C:\maven\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\maven\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;C:\maven\repository\org\springframework\spring-web\5.1.3.RELEASE\spring-web-5.1.3.RELEASE.jar;C:\maven\repository\org\springframework\spring-beans\5.1.3.RELEASE\spring-beans-5.1.3.RELEASE.jar;C:\maven\repository\org\springframework\spring-webmvc\5.1.3.RELEASE\spring-webmvc-5.1.3.RELEASE.jar;C:\maven\repository\org\springframework\spring-aop\5.1.3.RELEASE\spring-aop-5.1.3.RELEASE.jar;C:\maven\repository\org\springframework\spring-context\5.1.3.RELEASE\spring-context-5.1.3.RELEASE.jar;C:\maven\repository\org\springframework\spring-expression\5.1.3.RELEASE\spring-expression-5.1.3.RELEASE.jar;C:\maven\repository\org\springframework\boot\spring-boot-starter-web-services\2.1.1.RELEASE\spring-boot-starter-web-services-2.1.1.RELEASE.jar;C:\maven\repository\com\sun\xml\messaging\saaj\saaj-impl\1.5.0\saaj-impl-1.5.0.jar;C:\maven\repository\javax\xml\soap\javax.xml.soap-api\1.4.0\javax.xml.soap-api-1.4.0.jar;C:\maven\repository\org\jvnet\mimepull\mimepull\1.9.10\mimepull-1.9.10.jar;C:\maven\repository\org\jvnet\staxex\stax-ex\1.8\stax-ex-1.8.jar;C:\maven\repository\javax\xml\ws\jaxws-api\2.3.1\jaxws-api-2.3.1.jar;C:\maven\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\maven\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;C:\maven\repository\org\springframework\spring-oxm\5.1.3.RELEASE\spring-oxm-5.1.3.RELEASE.jar;C:\maven\repository\org\springframework\ws\spring-ws-core\3.0.4.RELEASE\spring-ws-core-3.0.4.RELEASE.jar;C:\maven\repository\org\springframework\ws\spring-xml\3.0.4.RELEASE\spring-xml-3.0.4.RELEASE.jar;C:\maven\repository\commons-io\commons-io\2.5\commons-io-2.5.jar;C:\maven\repository\org\projectlombok\lombok\1.18.4\lombok-1.18.4.jar;C:\maven\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\maven\repository\org\springframework\spring-core\5.1.3.RELEASE\spring-core-5.1.3.RELEASE.jar;C:\maven\repository\org\springframework\spring-jcl\5.1.3.RELEASE\spring-jcl-5.1.3.RELEASE.jar;C:\maven\repository\org\apache\cxf\cxf-spring-boot-starter-jaxws\3.3.1\cxf-spring-boot-starter-jaxws-3.3.1.jar;C:\maven\repository\org\apache\cxf\cxf-spring-boot-autoconfigure\3.3.1\cxf-spring-boot-autoconfigure-3.3.1.jar;C:\maven\repository\org\apache\cxf\cxf-rt-frontend-jaxws\3.3.1\cxf-rt-frontend-jaxws-3.3.1.jar;C:\maven\repository\xml-resolver\xml-resolver\1.2\xml-resolver-1.2.jar;C:\maven\repository\org\ow2\asm\asm\7.0\asm-7.0.jar;C:\maven\repository\org\apache\cxf\cxf-rt-bindings-soap\3.3.1\cxf-rt-bindings-soap-3.3.1.jar;C:\maven\repository\org\apache\cxf\cxf-rt-wsdl\3.3.1\cxf-rt-wsdl-3.3.1.jar;C:\maven\repository\wsdl4j\wsdl4j\1.6.3\wsdl4j-1.6.3.jar;C:\maven\repository\org\apache\cxf\cxf-rt-databinding-jaxb\3.3.1\cxf-rt-databinding-jaxb-3.3.1.jar;C:\maven\repository\org\apache\cxf\cxf-rt-bindings-xml\3.3.1\cxf-rt-bindings-xml-3.3.1.jar;C:\maven\repository\org\apache\cxf\cxf-rt-frontend-simple\3.3.1\cxf-rt-frontend-simple-3.3.1.jar;C:\maven\repository\org\apache\cxf\cxf-rt-ws-addr\3.3.1\cxf-rt-ws-addr-3.3.1.jar;C:\maven\repository\org\apache\cxf\cxf-rt-ws-policy\3.3.1\cxf-rt-ws-policy-3.3.1.jar;C:\maven\repository\org\apache\neethi\neethi\3.1.1\neethi-3.1.1.jar;C:\maven\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\maven\repository\org\apache\cxf\cxf-rt-transports-http\3.2.2\cxf-rt-transports-http-3.2.2.jar;C:\maven\repository\org\apache\cxf\cxf-core\3.2.2\cxf-core-3.2.2.jar;C:\maven\repository\com\fasterxml\woodstox\woodstox-core\5.0.3\woodstox-core-5.0.3.jar;C:\maven\repository\org\codehaus\woodstox\stax2-api\3.1.4\stax2-api-3.1.4.jar;C:\maven\repository\org\apache\ws\xmlschema\xmlschema-core\2.2.3\xmlschema-core-2.2.3.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.3\lib\idea_rt.jar" com.future.ws.WsApplication
Connected to the target VM, address: '127.0.0.1:8906', transport: 'socket'

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.1.RELEASE)

2022-05-14 12:15:53.083  INFO 15520 --- [           main] com.future.ws.WsApplication              : Starting WsApplication on DESKTOP-4C5EAT0 with PID 15520 (C:\me\future-learning\ws\target\classes started by 32631 in C:\me\future-learning\ws)
2022-05-14 12:15:53.096  INFO 15520 --- [           main] com.future.ws.WsApplication              : No active profile set, falling back to default profiles: default
2022-05-14 12:15:55.552  INFO 15520 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$8dab753d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-05-14 12:15:55.642  INFO 15520 --- [           main] .w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
2022-05-14 12:15:56.375  INFO 15520 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-05-14 12:15:56.430  INFO 15520 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-05-14 12:15:56.431  INFO 15520 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.13
2022-05-14 12:15:56.454  INFO 15520 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_144\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\nodejs\dev\nvm/npm;C:\nodejs\dev\nodejs;C:\nodejs\dev\nvm;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft VS Code\bin;C:\apache-maven-3.2.2\bin;C:\Program Files\Java\jdk1.8.0_144\bin;C:\Program Files\Java\jdk1.8.0_144\jre\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\MySQL\MySQL Server 5.7\bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Users\32631\AppData\Local\Programs\Python\Python36;C:\driver;;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Users\32631\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\32631\AppData\Local\Programs\Python\Python36\;C:\Users\32631\AppData\Local\Microsoft\WindowsApps;C:\Users\32631\AppData\Local\atom\bin;;C:\Users\32631\AppData\Local\Programs\Fiddler;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;.]
2022-05-14 12:15:56.850  INFO 15520 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-05-14 12:15:56.850  INFO 15520 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3432 ms
2022-05-14 12:15:58.190  INFO 15520 --- [           main] o.a.c.w.s.f.ReflectionServiceFactoryBean : Creating Service {http://impl.ws.ws.future.com/}FutureWebServiceImplService from class com.future.ws.ws.FutureWebService
2022-05-14 12:15:58.462  INFO 15520 --- [           main] org.apache.cxf.common.jaxb.JAXBUtils     : Failed to create NoEscapeHandler
2022-05-14 12:15:58.944  INFO 15520 --- [           main] org.apache.cxf.endpoint.ServerImpl       : Setting the server's publish address to be /ws/api
2022-05-14 12:15:59.282  INFO 15520 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2022-05-14 12:15:59.850  INFO 15520 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-05-14 12:15:59.860  INFO 15520 --- [           main] com.future.ws.WsApplication              : Started WsApplication in 8.411 seconds (JVM running for 12.791)

观察日志,也可以发现webservice服务的创建日志:

4.2 查看wsdl

webservice服务怎么看服务起来了没,一定要通过访问wsdl来确认:

以前没使用springboot的时候,都需要手动指定cxfservlet,都会设定一个url格式,如下:

   <servlet>
        <servlet-name>CXFService</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>CXFService</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

其中services表示url前缀为这个时候,使用cxfservice来处理请求,但是在springboot这边不需要指定,也有一个默认的url前缀,默认的就是services,如果想要修改,可以参考webserviceconfig里头,已经被我注释的部分代码。

一个完整的wsdl的连接还需要endpoint的相关信息,这个也在webserviceconfig里头有定义:

endpoint.publish("/ws/api");

所以wsdl的连接为:http://localhost:8080/services/ws/api?wsdl

注意,?wsdl这几个字符不能缺省。

4.3 soapui模拟请求ws服务

 确保服务起来了,现在通过soapui默认客户端请求。

如下修改参数的名称:

修改后如下:

 修改name的值,点击左上角的绿色三角形按钮,就发起请求了。

5 焕然醒悟

到这一步之前,似乎一番风顺,没错,确实没啥问题,但是妈呀,人家的参数是直接放在body里头,而不是像我们在body里头又套了一层方法标签和参数标签。

那么难到是webservice还可以不需要方法标签直接请求?更多的内容下篇继续解密。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐