须要准备的工具: html
从http://labs.renren.com/apache-mirror//ws/axis/1_4/axis-bin-1_4.zip下载axis_1.4,解压到某个目录(好比/media/tools/java/axis_1.4). 设置如下环境变量 java
export AXIS_HOME=/media/tools/java/axis_1.4 export PATH=${AXIS_HOME}/bin:${PATH} export AXIS_LIB=${AXIS_HOME}/lib AXIS_CP_PREFIX="/media/tools/java/axis-1.4/lib" for jarFile in `ls $AXIS_CP_PREFIX/*.jar` do AXIS_CLASSPATH=$AXIS_CLASSPATH:$AXIS_CP_PREFIX/$jarFile done export AXIS_CLASSPATH
假设在本地(localhost)端口(8888)上发布了一个SOAP Web Service(http://localhost:8888/MyWebApp/axis/Webservice.jws?wsdl), 采用以下的命令生成客户端接口: web
java -cp $AXIS_CLASSPATH org.apache.axis.wsdl.WSDL2Java http://localhost:8888/MyWebApp/axis/Webservice.jws?wsdl -o src/main/java
指令执行完毕后,将会在src/main/java目录产生相似以下四个java接口文件: shell
Webservice.java
WebserviceService.java
WebserviceServiceLocator.java
WebserviceSoapBindingStub.java
调用用Web service方法的范例代码: apache
WebserviceServiceLocator locator = new WebserviceServiceLocator(); Webservice wsUtil = locator.getWebservice(new URL("http://localhost:8888/MyWebApp/axis/Webservice.jws?wsdl")); String ret = wsUtil.sayHello("Archer");
PS: maven
<profile> <id>axistools</id> <activation> <activeByDefault>false</activeByDefault> </activation> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>axistools-maven-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>axis</groupId> <artifactId>axis-wsdl4j</artifactId> <version>1.5.1</version> </dependency> </dependencies> <configuration> <outputDirectory>${basedir}/src/main/java</outputDirectory> </configuration> </plugin> </plugins> </build> </profile>
须要mail.jar和activation.jar(能够从https://oss.sonatype.org/index.html 搜索下载)
mail.jar对应
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.4</version>
</dependency> 工具
activation.jar对应
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency> ui
而后把把mail.jar和activation.jar放到$AXIS_LIB目录下,并把他们添加到$AXIS_CLASSPATH中.
PS:这个是能够忽略的。不过之后构建web services都要用到的,仍是添加上的好
spa
将
<wsdl:fault name="Exception">
<soap12:fault use="literal" name="Exception"/>
</wsdl:fault>
替换成
<wsdl:fault name="Exception">
<soap:fault use="literal" name="Exception"/>
</wsdl:fault>
code