1.项目环境:axis1.4
2.pom.xml
<!-- https://mvnrepository.com/artifact/org.apache.axis/axis --> <dependency> <groupId>org.apache.axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency> <!-- https://mvnrepository.com/artifact/org.glassfish/javax.xml.rpc --> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.xml.rpc</artifactId> <version>3.2-b06</version> </dependency> <!-- https://mvnrepository.com/artifact/log4j/log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency><!-- https://mvnrepository.com/artifact/commons-logging/commons-logging --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-discovery/commons-discovery --> <dependency> <groupId>commons-discovery</groupId> <artifactId>commons-discovery</artifactId> <version>0.5</version> </dependency> <!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j --> <dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> <version>1.6.3</version> </dependency>
3.wsdl定义的java接口
String hello(@WebParam(name = "text") String text);
4.客户端代码
/** * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { String endpoint = "http://127.0.0.1:8080/helloWorld?wsdl"; String targetNamespace = "http://ws.sharp.com/"; //所调用接口的方法method String method = "hello"; try { // 创建一个服务(service)调用(call) Service service = new Service(); Call call = (Call) service.createCall();// 通过service创建call对象 // 设置service所在URL call.setTargetEndpointAddress(new java.net.URL(endpoint)); call.setOperationName(new QName(targetNamespace, method)); call.setUseSOAPAction(true); call.addParameter("text", XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型 String jsonString = (String) call.invoke(new Object[] { "我是测试数据" });//此处为数组,有几个变量传几个变量 System.out.println(jsonString); } catch (Exception e) { e.printStackTrace(); } }
5.调用结果
Hello 我是测试数据