java 使用AXIS调用远程的web service

时间:2022-01-25 21:11:49

  1、服务

    java 使用AXIS调用远程的web service

  2、代码

import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service; /**
* @Author:
* @Description:
* @Date:Created in 10:11 2018/9/7
* @Modified by:
**/
public class accessWeb { public static void main(String args[]) {
test();
} public static void test() {
String url = "http://15.23.25.21/spesvc/Ott/OttService.asmx";// 提供接口的地址
String soapaction = "http://oc.ctrchina.cn/";// 域名,这是在server定义的
String monitorDate = "2018-09-01";
Service service = new Service();
try {
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(soapaction, "GetPlayListGuidWithDate")); // 设置要调用哪个方法
call.addParameter(new QName(soapaction, "monitorDate"), // 设置要传递的参数
org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// (标准的类型)
call.setSOAPActionURI(soapaction + "GetPlayListGuidWithDate");
String res = String.valueOf(call.invoke(new Object[] { monitorDate }));// 调用方法并传递参数
System.out.println(res); } catch (Exception ex) {
ex.printStackTrace();
}
} }

  2、应用jar包

  java 使用AXIS调用远程的web service