小言_互联网的博客

webservice调用接口随记(axis)

357人阅读  评论(0)

使用的工具包是org.apache.axis1.4  ,需要的maven包如下:

        <!-- 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/axis/axis-jaxrpc -->
        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>
        <!--&lt;!&ndash; https://mvnrepository.com/artifact/commons-discovery/commons-discovery &ndash;&gt;-->
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.4</version>
        </dependency>

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

最后附上整体代码


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;

public class WebServiceTest {

    public static void main(String[] args) {

        String endPoint = "http://xxx/Service";// webservice地址
        String targetNamespace = "http://localhost:88/xxx/services";// 命名空间
        String methodName = "test";// 握手验证接口
        try {
            Service service = new Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(endPoint);
            call.setOperation(methodName);// 调用的方法
            call.setOperationName(new QName(targetNamespace, methodName));
            Object[] arr = new Object[2];//所需参数数组  参数个数需要与方法对应
            arr[0] = "11";//第一个参数
            arr[1] = "22";//第二个参数
            Object str = call.invoke(arr); // 调用方法
            System.out.println(str); // 返回
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}

 


转载:https://blog.csdn.net/wentwentzx/article/details/102487604
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场