SpringBoot对接web service服务对接

定义与描述

Web Service也称为web服务,它是一种跨编程语言和操作系统平台的远程调用技术。Web Service采用标准的SOAP协议传输(SOAP:Simple Object Access Protocol简单对象访问协议,soap属于w3c标准。并且soap协议是基于http的应用层协议传输xml数据)。Web Service采用WSDL作为描述语言,也就是Web Service 的使用说明书。并且W3C为Web Service制定了一套传输数据类型,使用xml进行描述,即XSD(XML Schema Datatypes),任何语言写的web Service 接口在发送数据的时候都要转换成WebService标准的XSD发送。

引入依赖

        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>javax.xml.rpc</groupId>
            <artifactId>javax.xml.rpc-api</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-saaj</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.3</version>
        </dependency>

        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.5</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

示例代码

import lombok.extern.slf4j.Slf4j;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

/**
 * Copyright (C), 2020-2022
  * FileName: AmlWebServiceClient
 * Author: be.insighted
 * Date: 2022/10/14 下午 05:39
 * Description: web service client
 */
@Slf4j
public class WebServiceClient {

    @Value("${web-service.uri}")
    private String URI;

    private String call(String input,String method) throws Exception {
        Service service = new Service();
        Call call = (Call) service.createCall();
        call.setTargetEndpointAddress(URI);
        call.setOperationName(new QName("http://ws.webapp.crla.hand.com", method));
        call.addParameter(new QName("http://ws.webapp.crla.hand.com", "in0"), XMLType.XSD_STRING, ParameterMode.IN);
        call.setUseSOAPAction(true);
        call.setSOAPActionURI("http://ws.webapp.crla.hand.com/method");
        call.setReturnType(XMLType.XSD_STRING);
        String result = (String) call.invoke(new Object[]{input});
        System.out.println("返回結果" + result);
        return result;
    }
}


版权声明:本文为Be_insighted原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。