依赖包:
<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.5</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-rpc-api</artifactId>
<version>2.5.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc</artifactId>
<version>1.1</version>
</dependency>
测试代码:
package cn.com.bsoft.ssdev.boot.weixin.test;
import org.apache.axis.client.Call;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;
import org.apache.axis.client.Service;
import static org.apache.axis.Constants.XSD_STRING;
public class MyTest {
public static void main(String[] args) throws Exception {
//doSelectRiskReportForm();
String flag = getFlag("310108194104032427");
System.out.println(flag);
}
public static void doSelectRiskReportForm() throws ServiceException {
//调用接口
//方法一:直接AXIS调用远程的web service
try {
String endpoint = "http://58.33.77.156:6887/get_report.asmx?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
String patientName = "310108194104032427"; // 参数名//对应的是 public String printWord(@WebParam(name = "settle_num") String settle_num);
// call.setOperationName("printWord"); // 调用的方法名//当这种调用不到的时候,可以使用下面的,加入命名空间名
call.setOperationName(new QName("http://tempuri.org/", "orientQueryLabReport"));// 调用的方法名
call.setSOAPActionURI("http://tempuri.org/orientQueryLabReport");
call.addParameter("sfzh", XSD_STRING, ParameterMode.IN);//参数名//XSD_STRING:String类型//.IN入参
call.setReturnType(XSD_STRING); // 返回值类型:String
String message = "310108194104032427";
String result = (String) call.invoke(new Object[] { message });// 远程调用
System.out.println("result is " + result);
} catch (Exception e) {
System.err.println(e.toString());
}
}
public static String getFlag(String sfzh) throws Exception{
String url = "http://58.33.77.156:6887/get_report.asmx?wsdl";
String namespace_uri = "http://tempuri.org/";
String soapActionURI = "http://tempuri.org/orientQueryLabReport";
Service service=new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(url);
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapActionURI);
call.setReturnType(XMLType.XSD_STRING);
call.setOperationName(new QName(namespace_uri, "orientQueryLabReport"));
// 所需参数
call.addParameter(new QName(namespace_uri,"sfzh"),XMLType.XSD_STRING,ParameterMode.IN);
// 执行,获取接口返回值
return call.invoke(new Object[]{sfzh}).toString();
}
}