加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Axis实践之Axis入门

发布时间:2020-12-17 01:19:55 所属栏目:安全 来源:网络整理
导读:关键字: web service axis apache 第一部分: 安装Axis 第一步: 下载Axis 从Apache网站下载Axis发布包: http://ws.apache.org/axis/ 我下载的是 Axis 1.4 Final 版 第二步: 解压Axis压缩包到tomcat/webapps目录下 把下载的axis-bin-1_4.zip包解压缩到一个

关键字: web service axis apache

第一部分: 安装Axis

第一步: 下载Axis
从Apache网站下载Axis发布包: http://ws.apache.org/axis/

我下载的是 Axis 1.4 Final 版


第二步: 解压Axis压缩包到tomcat/webapps目录下
把下载的axis-bin-1_4.zip包解压缩到一个文件夹,可以是任意的,但如果文件夹包含中文名时,在中间有些过程需要对中文进行一些处理,否则可能出错;
我把axis-bin-1_4.zip解压到 F:/AXIS_Study,解压后的目录结构是这样的:
F:/AXIS_Study
??? |
??? |____axis-bin-1_4?
??? |-----docs (文件夹)
??? |-----lib (文件夹)?

??? |-----samples (文件夹)?
??? |-----webapps (文件夹)?
??? |-----xmls (文件夹)?
??? |-----LICENSE?
??? |-----NOTICES?
??? |-----README?
??? |-----release-notes.html

第三步:启动tomcat,查看一下当前Axis中布署了哪些Web Service
打开浏览器,在地址栏输入: http://127.0.0.1:8000/axis/servlet/AxisServlet

?

浏览器显示结果:

?

这说明在Axis中已经布署了两个WebService,只不过这两个WebService都是Axis自带的,第一个是管理用的WebService,第二个是查看当前Axis版本信息的WebService。
大家可以点击相应的链接“wsdl”来看一下这两个WebService的 wsdl 文件。


结语: 至此,我们已经成功地把Axis 1.4 安装到Tomcat Web 服务器上了,接下来的目标是使用Axis来发布Web Service。


第二部分: 使用Axis发布Web Service
Axis提供两种方式将Java类发布成Web Services,这两种方式分别是:即时快速自动发布 和 通过配置文件进行发布,下面我们按顺序来讲如何使用这两种方式来发布WebService

即时快速自动发布:
第一步: 编写业务类
为了发布一个Web Service,首先必须要有业务类,为了节约时间,我写一个最简单的业务类:

?
注意,采用快速自动发布的Web Service的业务类不能带 package,也不能实现任何接口(Interface),因为Axis自动发布时不支持Package。


第二步:把SayHello发布为Web Service
把SayHello.java复制到 axis目录下的webapps/axis目录下,然后把文件扩展名改为:jws


第三步:访问刚发布的Web Service
打开浏览器,在地址栏里输入: http://127.0.0.1:8000/axis/SayHello.jws
浏览器显示结果如下:

There is a Web Service here

Click to see the WSDL

这表示Web Service已经发布成功了。我们可以点击连接“Click to see the WSDL ”来看看生成的wsdl文件:

Xml代码
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="http://127.0.0.1:8000/axis/SayHello.jws" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://127.0.0.1:8000/axis/SayHello.jws" xmlns:intf="http://127.0.0.1:8000/axis/SayHello.jws" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <!--
WSDL created by Apache Axis version: 1.4 Built on Apr 22,2006 (06:55:48 PDT)
? -->
- < wsdl:types >
- < schema elementFormDefault =" qualified " targetNamespace =" http://wsAgent " xmlns =" http://www.w3.org/2001/XMLSchema ">
- < element name =" request ">
- < complexType >
- < sequence >
? < element name =" str " type =" xsd:string " />
? </ sequence >
? </ complexType >
? </ element >
- < element name =" requestResponse ">
- < complexType >
- < sequence >
? < element name =" requestReturn " type =" xsd:string " />
? </ sequence >
? </ complexType >
? </ element >
? </ schema >
? </ wsdl:types >
- < wsdl:message name =" requestResponse ">
? < wsdl:part element =" impl:requestResponse " name =" parameters " />
? </ wsdl:message >
- < wsdl:message name =" requestRequest ">
? < wsdl:part element =" impl:request " name =" parameters " />
? </ wsdl:message >
- < wsdl:portType name =" ServerAgent ">
- < wsdl:operation name =" request ">
? < wsdl:input message =" impl:requestRequest " name =" requestRequest " />
? < wsdl:output message =" impl:requestResponse " name =" requestResponse " />
? </ wsdl:operation >
? </ wsdl:portType >
- < wsdl:binding name =" ServerAgentSoapBinding " type =" impl:ServerAgent ">
? < wsdlsoap:binding style =" document " transport =" http://schemas.xmlsoap.org/soap/http " />
- < wsdl:operation name =" request ">
? < wsdlsoap:operation soapAction ="" />
- < wsdl:input name =" requestRequest ">
? < wsdlsoap:body use =" literal " />
? </ wsdl:input >
- < wsdl:output name =" requestResponse ">
? < wsdlsoap:body use =" literal " />
? </ wsdl:output >
? </ wsdl:operation >
? </ wsdl:binding >
- < wsdl:service name =" ServerAgentService ">
- < wsdl:port binding =" impl:ServerAgentSoapBinding " name =" ServerAgent ">
? < wsdlsoap:address location =" http://127.0.0.1:8000/axis/services/HelloWorld2 " />
? </ wsdl:port >
? </ wsdl:service >
? </ wsdl:definitions >

第五步:写测试客户端
public static void main(String[] args) {
??try {
???String endpoint = "http://127.0.0.1:8000/axis/services/HelloWorldWSDD";

???Service service = new Service();
???Call call = (Call) service.createCall();

???call.setTargetEndpointAddress(new java.net.URL(endpoint));
???call.setOperationName("sayHello");

???String ret = (String) call.invoke(new Object[] { "Yu DouDou" });

???System.out.println("Return : [" + ret + "]");??} catch (Exception e) {???System.err.println(e.toString());??}?}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读