下载axis的相关工程包:
选中这2个文件下载:
1)axis-bin-1.4.zip 含有axis工程包,将工程包复制到tomcat里的webapps目录下;
2)axis-src-1.4.zip 源代码,可以查看下axis的实现。
axis里的即时发布:
1、新建HelloWS.java(没有建包名)类:
/**
* axis里的即时发布
* @author dellpc
*
*/
public class HelloWS { public String getResult(String a,String b)
{
String result = "a = "+a+"; b = "+b;
return result;
} }
2、将该java类,后缀名由java改成jws,放到axis工程包下:
3、重启tomcat,访问http://localhost:8080/axis/HelloWS.jws?wsdl
4、即时发布成功,创建即时发布的客户端,添加jar包:
5、编写客户端调用类,ClientJWS.java:
import javax.xml.namespace.QName; import org.apache.axis.client.Call;
import org.apache.axis.client.Service; /**
* 调用axis里的即时发布
* @author dellpc
*
*/
public class ClientJWS { public static void main(String[] args) {
String url = "http://localhost:8080/axis/HelloWS.jws";
Service service = new Service();
try
{
Call call =(Call)service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(url, "getResult"));
String result = (String)call.invoke(new Object[]{"aaa","bbb"});
System.out.println(result);
}
catch (Exception e)
{
e.printStackTrace();
}
} }
5、运行结果为:
a = aaa; b = bbb