axis1.4 java_axis1.4学习示例

%E6%9C%AA%E5%91%BD%E5%90%8D.jpg

1.在eclipse中创建web项目

2.再把jar包COPY到lib目录下

3.在web.xml中加入以下代码:

org.apache.axis.transport.http.AxisHTTPSessionListener

AxisServlet

Apache-Axis Servlet

org.apache.axis.transport.http.AxisServlet

AdminServlet

Axis Admin Servlet

org.apache.axis.transport.http.AdminServlet

100

SOAPMonitorService

SOAPMonitorService

org.apache.axis.monitor.SOAPMonitorService

SOAPMonitorPort

5001

100

AxisServlet

/services/*

SOAPMonitorService

/SOAPMonitor

4.创建服务端类

package server;

public class SayHello {

public String getName(String name)

{

return "hello "+name;

}

}

5.编写WebRoot\WEB-INF\deploy.wsdd文件

6.在tomcat中启动项目

7.

打开cmd 进入 目录 :WEB-INF\

输入部署命令(注意更改命令中服务的地址和端口)

java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services   deploy.wsdd

若显示

Processing file deploy.wsdd

Done processing

则表示发布服务成功

And now... Some Services

AdminService (wsdl)

AdminService

Version (wsdl)

getVersion

SayHello (wsdl)

getName

点击  SayHello (wsdl)   便会显示其XML ,点右健,查看源文件,保存XML为WebRoot\WEB-INF\SayHello.xml

9.创建客户端

编写axitDemo\WebRoot\WEB-INF\make.bat文件  内容如下

java -cp ".;lib\axis-ant.jar;lib\axis.jar;lib\commons-discovery-0.2.jar;lib\commons-logging-1.0.4.jar;lib\jaxrpc.jar;lib\log4j-1.2.8.jar;lib\log4j.properties;lib\saaj.jar;lib\wsdl4j-1.5.1.jar" org.apache.axis.wsdl.WSDL2Java -p %1 %2

10. 打开cmd进入WEB-INF目录

执行命令: make  com.webserivce  SayHello.xml

成功后会在WEB-INF目录下生成

com.webserivce  包下面会有java类 如下图:

%E6%9C%AA%E5%91%BD%E5%90%8D2.jpg

COPY    com.webserivce包到SRC目录下

12.编写客户端测试Client 类

package client;

import java.rmi.RemoteException;

import com.webserivce.SayHelloServiceLocator;

import com.webserivce.SayHello_PortType;

public class Client {

private SayHello_PortType dataService;

public Client()throws Exception{

SayHelloServiceLocator service= new SayHelloServiceLocator();

this.setDataService(service.getSayHello());

}

private String getName(String name) throws RemoteException{

return dataService.getName(name);

}

public static void main(String[] args)throws Exception {

Client c = new Client();

String a = c.getName("Test axis!");

System.out.println(a);

}

public SayHello_PortType getDataService() {

return dataService;

}

public void setDataService(SayHello_PortType dataService) {

this.dataService = dataService;

}

}

运行Client 类

hello  Test axis!

整个过程就完成啦。。。。。

posted on 2011-05-25 11:53 梓枫 阅读(704) 评论(0)  编辑  收藏 所属分类: webservice

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值