本站首页    管理页面    写新日志    退出

The Neurotic Fishbowl

[web Server技术]使用Axis发布简单的Web服务
狂飙的蜗牛 发表于 2006/6/15 14:26:06

使用Axis,要发布一个Web服务非常简单,简直不能再简单了,尽管看起来过程和相关代码有些长。我这个帖子里用到了这些软件:Axis 1.1、Eclipse 2.1和Eclipse的Tomcat插件2.2(Sysdeo Tomcat plugin)。发布的方法如下: 我要发布的服务是一个图书商店,公布的方法有添加图书addBook、列表图书listBooks、删除图书deleteBook等等,为简单起见这里就只发布一个添加图书方法,因为其他方法的发布是类似的。 1、首先在Eclipse里新建一个名为bookstore的Tomcat工程,注意要安装了前面说的Tomcat插件才有这个选项的。如果没有安 装可以建立一个java工程,然后手动建立必要的目录结构(WEB-INF等),并在Tomcat的server.xml里手动增加与项目对应的< context>项。 2、接下来建立图书类(com.bookstore.model.Book),图书有名称、ISDN号和页数三个属性,这是一个Bean类,代码如下: 500)this.width=500'>package com.bookstore.model;500)this.width=500'>500)this.width=500'>public class Book {500)this.width=500'>    private String name;500)this.width=500'>    private String ISDN;500)this.width=500'>    private int page;500)this.width=500'>500)this.width=500'>    public String getISDN() {500)this.width=500'>        return ISDN;500)this.width=500'>    }500)this.width=500'>500)this.width=500'>    public String getName() {500)this.width=500'>        return name;500)this.width=500'>    }500)this.width=500'>500)this.width=500'>    public int getPage() {500)this.width=500'>        return page;500)this.width=500'>    }500)this.width=500'>500)this.width=500'>    public void setISDN(String string) {500)this.width=500'>        ISDN = string;500)this.width=500'>    }500)this.width=500'>500)this.width=500'>    public void setName(String string) {500)this.width=500'>        name = string;500)this.width=500'>    }500)this.width=500'>500)this.width=500'>    public void setPage(int i) {500)this.width=500'>        page = i;500)this.width=500'>    }500)this.width=500'>500)this.width=500'>}500)this.width=500'> 3、接下来建立用来提供服务的类(com.bookstore.BookSvc),这个类就是实际的功能类了,它里面只有一个public的addBook()方法,而它的参数只有一个就是要添加的图书。代码如下: 500)this.width=500'>package com.bookstore;500)this.width=500'>500)this.width=500'>import com.bookstore.model.Book;500)this.width=500'>500)this.width=500'>public class BookSvc {500)this.width=500'>    500)this.width=500'>    public void addBook(Book book){500)this.width=500'>        //here you save a book into database500)this.width=500'>        System.out.println("Book has been added.");500)this.width=500'>    }500)this.width=500'>}500)this.width=500'> 4、现在,把下载来的Axis解压缩到一个文件夹,这里假设你解到C:\axis-1_1。把C:\axis-1_1\webapps\axis\ WEB-INF\lib目录下的所有.jar文件复制到你的这个web应用程序的WEB-INF\lib下,再把C:\axis-1_1\webapps \axis\WEB-INF目录下的web.xml复制到你的web应用程序的WEB-INF下。这个步骤相当于在你的web应用程序中配置了Axis。 5、为了让Axis知道你要发布哪些服务,你得在WEB-INF下建立一个名为server-config.wsdd的文件,内容如下: 500)this.width=500'><?xml version="1.0" encoding="UTF-8"?>500)this.width=500'><deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">500)this.width=500'> <globalConfiguration>500)this.width=500'>  <parameter name="adminPassword" value="admin"/>500)this.width=500'>  <parameter name="attachments.Directory" value="C:\eclipse\workspace\bookstore\WEB-INF\attachments"/>500)this.width=500'>  <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>500)this.width=500'>  <parameter name="sendXsiTypes" value="true"/>500)this.width=500'>  <parameter name="sendMultiRefs" value="true"/>500)this.width=500'>  <parameter name="sendXMLDeclaration" value="true"/>500)this.width=500'>  <parameter name="axis.sendMinimizedElements" value="true"/>500)this.width=500'>  <requestFlow>500)this.width=500'>   <handler type="java:org.apache.axis.handlers.JWSHandler">500)this.width=500'>    <parameter name="scope" value="session"/>500)this.width=500'>   </handler>500)this.width=500'>   <handler type="java:org.apache.axis.handlers.JWSHandler">500)this.width=500'>    <parameter name="scope" value="request"/>500)this.width=500'>    <parameter name="extension" value=".jwr"/>500)this.width=500'>   </handler>500)this.width=500'>  </requestFlow>500)this.width=500'> </globalConfiguration>500)this.width=500'> <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>500)this.width=500'> <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>500)this.width=500'> <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>500)this.width=500'> <service name="Version" provider="java:RPC">500)this.width=500'>  <parameter name="allowedMethods" value="getVersion"/>500)this.width=500'>  <parameter name="className" value="org.apache.axis.Version"/>500)this.width=500'> </service>500)this.width=500'> <service name="BookSvc" provider="java:RPC">500)this.width=500'>  <parameter name="allowedMethods" value="*"/>500)this.width=500'>  <parameter name="className" value="com.bookstore.BookSvc"/>500)this.width=500'> </service>500)this.width=500'> <service name="AdminService" provider="java:MSG">500)this.width=500'>  <parameter name="allowedMethods" value="AdminService"/>500)this.width=500'>  <parameter name="enableRemoteAdmin" value="false"/>500)this.width=500'>  <parameter name="className" value="org.apache.axis.utils.Admin"/>500)this.width=500'>  <namespace>http://xml.apache.org/axis/wsdd/</namespace>500)this.width=500'> </service>500)this.width=500'> <transport name="local">500)this.width=500'>  <responseFlow>500)this.width=500'>   <handler type="LocalResponder"/>500)this.width=500'>  </responseFlow>500)this.width=500'> </transport>500)this.width=500'> <transport name="http">500)this.width=500'>  <requestFlow>500)this.width=500'>   <handler type="URLMapper"/>500)this.width=500'>   <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>500)this.width=500'>  </requestFlow>500)this.width=500'> </transport>500)this.width=500'></deployment> 这个文件里发布了三个服务:Version、AdminService和我们的BookSvc。还有一个方法可以生成这个文件,好象Axis推荐使用这种生成的方法,就是在同样目录下写一个deploy.wsdd文件(如果不想看可以直接跳到下一步),内容如下: 500)this.width=500'><deployment xmlns="http://xml.apache.org/axis/wsdd/"500)this.width=500'>            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">500)this.width=500'> <service name="BookSvc" provider="java:RPC">500)this.width=500'>  <parameter name="className" value="com.bookstore.BookSvc"/>500)this.width=500'>  <parameter name="allowedMethods" value="*"/>500)this.width=500'> </service>500)this.width=500'></deployment> 也就是说deploy.wsdd里只包含关于我们的服务的描述,确认Tomcat已经启动,然后在同一目录下用下面这个命令生成server-config.wsdd文件: 500)this.width=500'>java org.apache.axis.client.AdminClient -lhttp://localhost:8080/bookstore/services/AdminService deploy.wsdd 其中bookstore是我这个web应用程序的虚拟路径。 6、重新启动Tomcat,访问路径http://localhost:8080/bookstore/services,就可以看到现在发布了三个Web服务,如下图。点击每个服务后的wsdl链接可以看到对应的WSDL描述。 500)this.width=500'>

阅读全文(1955) | 回复(0) | 编辑 | 精华

 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)

 
 



The Neurotic Fishbowl

.: 公告


Bloginess

«September 2025»
123456
78910111213
14151617181920
21222324252627
282930

.: 我的分类(专题)

首页(31)
原创(9)
Ajax技术(1)
随笔(1)
web Server技术(6)


In the Bowl

.: 最新日志

NewsBar真的能赚钱吗?
学习蜡烛图
2009-02-19(汇市报道)
2009-2-18
正式进入汇市
jsp上传图片
一个MM搞笑的Google搜索记录
两头猪的精典对白
一个未婚男人的自述
寂寞而高贵的武士-----野蛮人(一)


.: 最新回复

回复:axis2安装步骤
回复:axis2安装步骤
回复:安装序列号集锦
回复:七大人物套装的背景知识
回复:一个未婚男人的自述
回复:2009-02-19


The Fishkeeper
blog名称:狂飙的蜗牛
日志总数:31
评论数量:19
留言数量:0
访问次数:158465
建立时间:2006年6月13日



Text Me

.: 留言板

签写新留言


Other Fish in the Sea

.: 链接


 pandaboss.bolg.sohu.com




站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.031 second(s), page refreshed 144769955 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号