使用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类,代码如下:
3、接下来建立用来提供服务的类(com.bookstore.BookSvc),这个类就是实际的功能类了,它里面只有一个public的addBook()方法,而它的参数只有一个就是要添加的图书。代码如下:
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的文件,内容如下:
这个文件里发布了三个服务:Version、AdminService和我们的BookSvc。还有一个方法可以生成这个文件,好象Axis推荐使用这种生成的方法,就是在同样目录下写一个deploy.wsdd文件(如果不想看可以直接跳到下一步),内容如下:
也就是说deploy.wsdd里只包含关于我们的服务的描述,确认Tomcat已经启动,然后在同一目录下用下面这个命令生成server-config.wsdd文件:
其中bookstore是我这个web应用程序的虚拟路径。
6、重新启动Tomcat,访问路径http://localhost:8080/bookstore/services,就可以看到现在发布了三个Web服务,如下图。点击每个服务后的wsdl链接可以看到对应的WSDL描述。
相关链接:
评论
And now... Some Services
AXIS error
Sorry, something seems to have gone wrong... here are the details:
Fault - Could not find class for the service named: com.bookstore.BookSvc
Hint: you may need to copy your class files/tree into the right location (which depends on the servlet system you are using).; nested exception is:
java.lang.ClassNotFoundException: com.bookstore.BookSvc
AxisFault
faultCode: { http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString: Could not find class for the service named: com.bookstore.BookSvc
Hint: you may need to copy your class files/tree into the right location (which depends on the servlet system you are using).; nested exception is:
java.lang.ClassNotFoundException: com.bookstore.BookSvc
faultActor:
faultNode:
faultDetail:
另外,我想自动生成server-config.wsdd就已经出错了,为什么?
D:/Eclipse/workspace/bookstore/WEB-INF>java org.apache.axis.client.AdminClient -l http://localhost:8080/bookstore/services/AdminServic deploy.wsdd
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/client/AdminClient
RE:另外,我想自动生成server-config.wsdd就已经出错了,为什么?
检查你的系统变量设置,确定包含axis.jar
按照你的步骤,比较顺利地实现了bookstore,除了一点小挫折:
http://www.cnblogs.com/zhengyun_ustc/archive/2005/06/14/174348.html([Java]Axis需要高版本的J2sdk: j2sdk-1_4_2_08)
C:/>java -cp %AXISCLASSPATH% org.apache.Axis.client.AdminClient deploy.wsdd
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/Axis/clien
t/AdminClient
环境变量
AXIS_HOME=D:/Tomcat/webapps/axis/WEB-INF
AXISCLASSPATH=.;%AXIS_HOME%/lib/axis.jar;%AXIS_HOME%/lib/axis-ant.jar;%AXIS_HOME%/lib/commons-discovery-0.2.jar;%AXIS_HOME%/lib/commons-logging-1.0.4.jar;%AXIS_HOME%/lib/jaxrpc.jar;%AXIS_HOME%/lib/saaj.jar;%AXIS_HOME%/lib/wsdl4j-1.5.1.jar;%AXIS_HOME%/lib/log4j-1.2.8.jar;
直接用DII的方式写一个简单的webservice然后远程调用*.jws就正常,现在这个服务里加了访问数据库的代码在里面,我在网上查看了资料说这种情况一般要发布服务,按照那些操作在命令行执行总是出现如上的错误,请问是什么原因
如果源码中(以Hello为例)出现了package server,然后运行 http://localhost:8080/axis/Hello.jws?WSDL想直接生成wsdl时,这时axis是生成了.class文件,不过是在axis/WEB-INF/jwsClasses/server下的Hello.class.也就是说.class文件已经打包 ,但ie报错说找不到axis/WEB-INF/jwsClasses下的Hello.class,这时即使copy一个.class文件放到axis/WEB-INF/jwsClasses下,会报另一个错:
AXIS error
Sorry, something seems to have gone wrong... here are the details:
Exception - java.lang.NoClassDefFoundError: Hello (wrong name: server/Hello)
这个是不是说有package的不能直接生成呢?
呵呵,刚开始接触axis,不是很明白.
D:/Tomcat 4.1/webapps/axis/WEB-INF>java -cp %AXISCLASSPATH% org.apache.axis.clie
nt.AdminClient deploy.wsdd
log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectR
esourceBundle).
log4j:WARN Please initialize the log4j system properly.
Processing file deploy.wsdd
Exception: AxisFault
faultCode: { http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.net.ConnectException: Connection refused: connect
faultActor:
faultNode:
faultDetail:
{ http://www.cnblogs.com/bjzhanghao/archive/2004/10/09/<a%20target="> http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Conne
ction refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
ketFactory.java:135)
at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
ketFactory.java:99)
at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:1
31)
at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.ja
va:370)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:88)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
y.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:147)
at org.apache.axis.client.Call.invokeEngine(Call.java:2719)
at org.apache.axis.client.Call.invoke(Call.java:2702)
at org.apache.axis.client.Call.invoke(Call.java:1738)
at org.apache.axis.client.AdminClient.process(AdminClient.java:438)
at org.apache.axis.client.AdminClient.process(AdminClient.java:403)
at org.apache.axis.client.AdminClient.process(AdminClient.java:409)
at org.apache.axis.client.AdminClient.process(AdminClient.java:319)
at org.apache.axis.client.AdminClient.main(AdminClient.java:462)
{ http://www.cnblogs.com/bjzhanghao/archive/2004/10/09/<a%20target="> http://xml.apache.org/axis/}hostname:MICROSOF-8768E9
这是什么错啊。