基于Axis1.4的webservice接口开发(接口调用)
一、webservice接口代码参考上一篇博客:
http://www.cnblogs.com/zhukunqiang/p/7125668.html
二、代码部分
1、新建Web Project工程,取名为axiswebserviceClint,并导入Axis1.4所需jar包(将jar包粘贴到lib目录)。
2、新建webservice接口调用类:
package com.no8.clint;
import java.net.URL;
import javax.xml.rpc.ServiceException;
import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class WebClient {
public static void main(String[] args) throws Exception {
String endpoint = "http://localhost:8080/axiswebservice/services/HelloWorld?wsdl";
//创建一个服务(service)调用(call)
Service service = new Service();
Call call = (Call) service.createCall(); //设置service所在的url
call.setTargetEndpointAddress(new java.net.URL(endpoint)); call.setOperation("sayHello"); String ret = (String)call.invoke(new Object[]{"张三"});
System.out.println(ret);
}
}
3、点击运行java类(直接运行java文件,不需要将web工程部署到Tomcat中就可直接运行):
调用成功!