Home >Java >javaTutorial >How SpringBoot uses axis to call the webservice interface

How SpringBoot uses axis to call the webservice interface

王林
王林forward
2023-05-11 13:28:062245browse

WebService

Definition

How SpringBoot uses axis to call the webservice interface

Personal understanding

Through Du Niang and other methods, my personal understanding is that it is a disguised soap protocol plus xml process Single processing,

Practice

webservice common sense

A webservice interface publishing address is often similar:

  • qq Online verification interface:

www.webxml.com.cn/webservices…

  • Other testable interfaces:

emailEmail address interface: www.webxml.com.cn/WebServices…

National weather conditions interface:

www.webxml.com.cn/WebServices…

qq Take the online interface verification interface as an example

Add after the interface:/wsdl www.webxml.com.cn/webservices…

Access and view and find the one defined in the figure below Content: Pay attention to using the associated key to find the corresponding necessary parameters.

How SpringBoot uses axis to call the webservice interface

maven uses axis

Apply dependencies (cannot be missing and required)

        <!-- https://mvnrepository.com/artifact/org.apache.axis/axis -->
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j -->
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.2</version>
        </dependency>
<!--        解决cell 转换问题-->
        <!-- https://mvnrepository.com/artifact/javax.xml/jaxrpc-api -->
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>jaxrpc-api</artifactId>
            <version>1.1</version>
        </dependency>
<!--       解析调用结果以及数据转换包-->
        <!-- https://mvnrepository.com/artifact/commons-discovery/commons-discovery -->
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.2</version>
        </dependency>

Code (paste available)

@Test
public void testWebService() {
    try {
        //wsdl地址
        String endpoint = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx";
        //命名空间
        String namespace = "http://WebXml.com.cn/";
        //服务名
        String serviceName = "qqOnlineWebService";
        //方法名
        String methodName = "qqCheckOnline";
        //soapAction
        String soapAction = "http://WebXml.com.cn/qqCheckOnline";

        Service service = new Service();
        Call call = (Call) service.createCall();
        //设置响应超时
        call.setTimeout(3000);
        //设置地址
        call.setTargetEndpointAddress(new java.net.URL(endpoint));
        //设置方法名
        call.setOperationName(new QName(namespace, methodName));

        //设置参数
        call.addParameter(new QName(namespace, "qqCode")
                , org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        //设置返回类型
        call.setReturnType(XMLType.XSD_SCHEMA);
        //启用soap
        call.setUseSOAPAction(true);
        //设置soapAction
        call.setSOAPActionURI(soapAction);
        //设置服务名
        SOAPService soapService = new SOAPService();
        soapService.setName(serviceName);
        call.setSOAPService(soapService);
        Schema result = (Schema) call.invoke(new Object[]{"xxxxx"});
        for (int i = 0; i < result.get_any().length; i++) {
            System.out.println(result.get_any()[i]);
        }
    } catch (Exception e) {
        log.error("ddd", e);
    }
}

Regarding the above code, let me complain here. There are actually many examples of this on the Internet, but problems will occur when actually calling it. Note:

  • Setting parameters

How SpringBoot uses axis to call the webservice interface

  • Get the results

How SpringBoot uses axis to call the webservice interface

##xxxx needs to fill in the real QQ number

The above is the detailed content of How SpringBoot uses axis to call the webservice interface. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete