WebService开发 Axis Client

1,814 阅读2分钟

开发中或多或少会遇到第三方使用webservice这种方式提供服务,网上资料错综繁杂,很难找到合适自己的工具,本文使用Axis命令行的方式生成客户端代码,并展示最终如何调用。

1、客户端工具

1.1 官网下载Axis-1.4

mirrors.tuna.tsinghua.edu.cn/apache/axis…

1.2 lib文件夹中引入额外的jar包(非必要,仅用作去除警告)

javax.activation-api-1.2.0.jar mail-1.4.jar

2、使用命令行生成java客户端代码

2.1 常用参数说明

-Djava.ext.dirs 可以批量引入jar包 此处为/axis-1_4/lib的(绝对/相对)路径
-p 指定生成Java代码的包名
-o 指定生成Java代码的路径(可以为空,空时生成在命令执行时所在的文件夹)

2.2 生成代码命令行

java -Djava.ext.dirs=axis-1_4/lib/ org.apache.axis.wsdl.WSDL2Java http://oa.medbanks-test.cn//services/WorkflowService?wsdl -p com.hussein

2.3 查看结果

3、如何使用

3.1 引入相关全量maven依赖

    <dependencies>
        <!-- axis 1.4 jar start -->
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-ant</artifactId>
            <version>1.4</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.4</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>javax.activation-api</artifactId>
            <version>1.2.0</version>
        </dependency>
        <!-- axis 1.4 jar end -->
    </dependencies>

3.2 代码部分

public class App {

    public static void main(String[] args) throws RemoteException, ServiceException {
        WorkflowServiceLocator workflowServiceLocator = new WorkflowServiceLocator();
        WorkflowServicePortType workflowServiceHttpPort = workflowServiceLocator.getWorkflowServiceHttpPort();
        int count = workflowServiceHttpPort.getToDoWorkflowRequestCount(1, new String[]{});
        System.out.println(count);
    }
}

4、本文项目

4.1 项目地址

github.com/hwangsiyuan…

4.2 已经把axis工具放在项目resoures中,可以下载解压直接使用