根据url 调用:http://10.220.105.60:8080/pdyjws/baseMethod.asmx
/**
* 调用webservice接口,返回string类型的json值
* @return
*/
public String getWebServices(){
//获取webservice接口地址
String url = "http://10.220.105.60:8080/pdyjws/baseMethod.asmx";
//获取域名地址,server定义的
String soapaction = "http://tempuri.org/";
Service service = new Service();
//调用的方法
String method="getDailyFast";
//调用的参数
String startdate="2019-02-11";
String enddate="2019-02-12";
String result="";
try {
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
//设置要调用的方法
call.setOperationName(new QName(soapaction,method));
call.addParameter(new QName(soapaction, "startdate"), // 设置要传递的参数--要和接口方提供的参数名一致
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName(soapaction, "enddate"), // 设置要传递的参数
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
//设置要返回的数据类型
call.setReturnType(new QName(soapaction,method), String.class);
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapaction+method);
//调用方法并传递参数
result = (String) call.invoke(new Object[]{startdate,enddate});
} catch (ServiceException e) {
bislogger.error("[PdfDataTask][getWebServices]Exception1",e);
} catch (Exception e) {
bislogger.error("[PdfDataTask][getWebServices]Exception2",e);
}
return result;
}
需要的jar包,这些jar包不能少:
<!-- https://mvnrepository.com/artifact/org.apache.axis/axis -->
<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>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.7</version><!--$NO-MVN-MAN-VER$-->
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.7</version><!--$NO-MVN-MAN-VER$-->
</dependency>