JAVA调用web service(axis方式)
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class Test {
public static void main(String[] args) {
//testAddCustomer();
//testValidateLogin();
testGetMessageInfo();
}
public static void testAddCustomer(){
try {
String endpoint = "http://localhost:8080/ehomeSer/services/WebServiceCenter?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName(new QName("http://webservice.ehome.qinan.com","addCustomer"));
call.addParameter("name", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter("key_code", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter("idcard", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter("pwd", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter("tel", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter("address", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://localhost:8080/ehomeSer");
String result = (String)call.invoke(new Object[]{"张三","KEY123","46368119900125794X","123456","0731-1231321","长沙市"});
System.out.println("addCustomer result is "+result);
}
catch (Exception e) {
System.err.println(e.toString());
}
}
}
关注微信公众号福利!!!
回复关键字「666」获取一份最新 Java 架构资料,你要的都有!
回复关键字「Java」获取JVM, 多线程等Java技术系列教程;
回复关键字「spring」获取Spring, Spring Boot, Spring Cloud教程;
回复关键字「架构」获取分布式、微服务、架构、高并发等系列干货;
回复关键字「面试」获取各种 Java 面试题及答案、面试实战经验;