使用Axis开发Web Service应用及调用
2007-02-04 15:51
441 查看
如何使用Axis开发Webservice应用程序
转自:中华网科技 http://tech.china.com 2005-05-27 14:06:55Axis是Apache的一个开源web service引擎。它目前最为成熟的开源web service引擎之一。下面我主要介绍一下如何使用该Axis开发您的web service 服务。
1、安装
以tomcat4.1为服务器,下面说明如何安装axis:
1.解压下载后的包,将包中axis目录复制到tomcat目录下的webapps目录下;
2.将axis/WEB-INF/lib目录下类文件复制到tomcat目录下的common/lib目录下;
3.重新启动tomcat;
4.访问http://localhost:8080/axis/happyaxis.jsp,如果能访问,表示安装成功;
2、开发webservice服务
a.编写普通类文件,如下所示:
//文件名:Test.java
import java.util.*;
public class Test
{
//fields
private String name="gaga";
private int age=20;
private List items=new ArrayList();
//method at here.
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public List getItems()
{
return items;
}
}
将本文件(Test.java)复制到Axis目录下,并将其更名为Test.jws;
b.访问http://localhost:8080/axis/Test.jws,Axis就会编译该文件,并将其部署到系统中,下面你就可以开发web service的客户端程序了;
3、开发客户端程序
下面是客户端程序:
import org.apache.axis.client.*;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class TestWebService
{
public static void main(String args[])
{
System.out.println("Start invoking....");
try {
String endpoint =
"http://localhost:8080/axis/Test.jws";
//你写的那个文件
Service service = new Service();
Call call = (Call)
service.createCall();
call.setTargetEndpointAddress
( new java.net.URL(endpoint) );
call.setOperationName("getAge");
//填写你要调用的方法名称
int ret =Integer.parseInt
(("" + call.invoke( new Object[] {} )));
System.out.println(ret);
} catch (Exception e) {
System.err.println(e.toString());
}
System.out.println("Finished the invoking.");
}
}
关于业务调用封装到服务端程序里,然后部署就可以了,就这么简单。
相关文章推荐
- 速动画教程第二十五集 使用 xfire 开发 web service 应用
- android-------使用Android应用调用Web Service
- (引用)Java RPC通信机制之SOAP:应用Apache Axis进行Web Service开发
- 使用axis 开发web service的build.xml
- 使用Axis开发Web Service程序
- 使用Axis 开发Web Service服务器端
- 使用Eclipse的Axis1.4插件开发Web Service及客户端
- 使用Axis开发Web Service程序
- 使用Axis开发Web Service程序
- Android 程式开发:(四)使用Intent调用“内置”应用 —— 4.3配置Intent-Filter
- 使用Axis开发Web Service程序
- JSP学习笔记(一百二十三):使用axis1.4开发webservice应用(二)
- 使用Axis开发Web Service程序
- 使用Axis开发Web Service程序
- 使用Axis开发Web Service程序 整合 spring
- android开发(26) 和其他应用交换数据方式一,使用intent指定自定义action调用其他程序里的activity,并获得其返回的结果
- 使用Axis开发Web Service程序
- Sharepoint2010应用开发二:使用列表 Web Service操作列表
- 详解怎样使用Axis开发Web Service的实例(转)
- JAVA使用XFire开发Web Service客户端几种调用方式