首先我们是客户端,我们要找一个服务端来配合我们调试,可以在这个网址里找个你喜欢的免费服务WEB服务(Web Servicrs)| 免费WEB服务 | 商业WEB服务 | XML Web Servicrs - WEBXML
比如下面这个查手机号归属地的:
我们新建一个maven工程,在pom文件里引用axis依赖(可以在此连接Apache 轴对axis进行了解)。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yulong.wsdltest</groupId>
<artifactId>wsdltest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<fastjson.version>1.2.83</fastjson.version>
</properties>
<dependencies>
<!--wsdl-->
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.sixdimensions.commons.osgi.wrapper</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>apache-log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>org.lucee</groupId>
<artifactId>saaj</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
</dependency>
</dependencies>
</project>
然后我们创建一个client。
填入刚刚的wsdl url(http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl)。
然后就生成了相应的类。
我们再写个测试类调用一下看看。
public static <MobileCodeWSSoap> void main(String[] argv) throws ServiceException, RemoteException {
MobileCodeWS service = new MobileCodeWSLocator();
MobileCodeWSSoap_PortType port = service.getMobileCodeWSSoap();
String body = port.getMobileCodeInfo("15715700000",null);
System.out.println(body);
}
发现完美运行: