POM引入
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.1</version>
</dependency>
<!-- 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/javax.xml/jaxrpc-api -->
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc-api</artifactId>
<version>1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.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>
实际项目中使用的调用主方法:
public String callService(String pcbNo) {
try {
// 直接引用远程的wsdl文件
String endpoint = "http://192.168.1.102:8080/qualification/ws/lyGwData?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
// WSDL里面描述的接口名称(命名空间+方法名)
call.setOperationName(new QName("http://gw.webservice.com/","searchGwIpoMainByPcbNo"));
call.setEncodingStyle("UTF-8");
call.addParameter("pcbNo",
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);// 接口的参数
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
Object result = call.invoke(new Object[] { pcbNo});
//打印回值
log.info("webservice response :{}",result.toString());
return result.toString();
} catch (Exception e) {
System.err.println(e.toString());
}
return null;
}