笔者近期要为项目加入webservice模块,但是看了网上的教程文章一阵碰壁后才学会如何加入ws,所以写一篇自己增加webservice的文章,为广大网友提供另一个方面的教程,希望对大家有所启迪。
前提:已有一个web项目,名为testAxis ,路径:E:/eclipseWork/testAxis
1、下载axis包
http://www.apache.org/dyn/closer.cgi/ws/axis/1_4
解压到 E:/axis-1_4
2、配置axis
将 E:/axis-1_4/lib 里面的文件拷到 E:/eclipseWork/testAxis/web/WEB-INF/lib 下
编辑 E:/eclipseWork/testAxis/web/WEB-INF/web.xml
在
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
前加入:
编辑tomcat/conf/server.xml
在
<Host name="localhost" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
后加入:
<Context docBase="E:/eclipseWork/testAxis/web" path="/testAxis" reloadable="true" />
启动tomcat 访问: http://localhost:8080/testAxis/services
可以看到:
And Now... Some Services
3、编写webservice服务端
在web项目下新建一个类
4、注册服务
在 E:/eclipseWork/testAxis/web/WEB-INF 下新建文本文件 deploy.wsdd
启动刚刚配置好的项目,并确保访问http://localhost:8080/testAxis/services页面显示正常
打开cmd
cd E:/eclipseWork/testAxis/web/WEB-INF
E:/eclipseWork/testAxis/web/WEB-INF>java -Djava.ext.dirs=E:/eclipseWork/testAxis/web/WEB-INF/lib org.apache.axis.client.AdminClient -lhttp://localhost:8080/testAxis/servlet/AxisServlet deploy.wsdd
成功的话会显示:
Processing file deploy.wsdd
<Admin>Done processing</Admin>
并在 E:/eclipseWork/testAxis/web/WEB-INF 下面产生 server-config.wsdd 文件
重启tomcat,并访问 http://localhost:8080/testAxis/services 会发现多出来一个service
And Now... Some Services
就说明你的配置成功了
5、测试webservice
访问 http://localhost:8082/testAxis/services/SayHello?wsdl
打开cmd
cd E:/eclipseWork/testAxis
E:/eclipseWork/testAxis>java -Djava.ext.dirs=E:/eclipseWork/testAxis/web/WEB-INF
/lib org.apache.axis.wsdl.WSDL2Java -oE:/eclipseWork/testAxis/src -pcom.neo.clie
nt http://localhost:8082/testAxis/services/SayHello?wsdl
执行后在src下产生 E:/eclipseWork/testAxis/src/com/neo/client 文件夹里面有四个java文件:
HelloWorld.java
HelloWorldService.java
HelloWorldServiceLocator.java
SayHelloSoapBindingStub.java
在com.neo.client下新建一个类
直接运行,如果打印出 hello 就说明客户端调用成功!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。