1 导入pom文件
<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>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</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>
2 封装调用类
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AxisWebServiceUtils {
private static Logger logger = LoggerFactory.getLogger(AxisWebServiceUtils.class);
private static Service service = new Service();
/**
* 获取调用对象Call
* @param Url 调用链接
* @param qName 方法所在类名
* @param method 调用方法名
* @return
*/
public static Call axisSevice(String Url, String qName, String method) {
Call call = null;
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress(Url);
call.setOperationName(new QName(qName, method));
} catch (ServiceException e) {
logger.error("调用接口出错 url:{} QName:{} method:{} Exception:{} ", Url, qName, method, e);
return call;
}
return call;
}
}
3 调用
String result = (String)
AxisWebServiceUtils.axisSevice("url",
"WebServiceClassName", "WebServiceMethodName")
.invoke(new Object[] {param1, list.toArray(),param2,param3});