SpringBoot整合webservice服务

2020-05-27  本文已影响0人  渐渐_薇薇
什么是webservice?

简单来说,webservice就是远程调用技术,也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立的通讯技术。是:通过SOAP在Web上提供的软件服务,使用WSDL文件进行说明,并通过UDDI进行注册。
XML:(Extensible Markup Language)扩展型可标记语言。面向短期的临时数据处理、面向万维网络,是Soap的基础。
Soap:(Simple Object Access Protocol)简单对象存取协议。是XML Web Service 的通信协议。当用户通过UDDI找到你的WSDL描述文档后,他通过可以SOAP调用你建立的Web服务中的一个或多个操作。SOAP是XML文档形式的调用方法的规范,它可以支持不同的底层接口,像HTTP(S)或者SMTP。
WSDL:(Web Services Description Language) WSDL 文件是一个 XML 文档,用于说明一组 SOAP 消息以及如何交换这些消息。大多数情况下由软件自动生成和使用

整合webservice

1、添加依赖支持

 <!-- CXF dependency -->
 <dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
    <version>3.2.4</version>
 </dependency>
<!-- CXF webservice -->

2、创建webservice接口

@WebService
public interface IDataSyncService {

    @WebMethod
    String dataSync(@WebParam(name = "paramXml") String paramsXML);
}

3、接口实现类

//name暴露的服务名称, targetNamespace:命名空间,设置为接口的包名倒写(默认是本类包名倒写). endpointInterface接口地址
@WebService(serviceName  = "DataSyncService" ,targetNamespace ="http://service.webservice.bucket.com/" ,endpointInterface = "com.bucket.webservice.service.IDataSyncService")
@Component
public class DataSyncService implements IDataSyncService {
    @Override
    public String dataSync(String paramsXML) {
        return "suc";
    }
}

4、新建webservice配置类CxfConfig

@Configuration
public class CxfConfig {

    @Autowired
    private Bus bus;
    @Autowired
    private IDataSyncService dataSyncService;

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }


    @Bean
    public Endpoint endpointIscUserWebService() {
        EndpointImpl endpoint = new EndpointImpl(bus,dataSyncService);
        endpoint.publish("/dataSyncService");//接口发布在 /dataSyncService 目录下
        return endpoint;
    }
}

启动项目后,游览器访问 http://localhost:项目端口/services/CXFServlet注册地址 本例访问
http://127.0.0.1:8500/uim/services/dataSyncService?wsdl

image.png
上一篇下一篇

猜你喜欢

热点阅读