“org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-INF/xfire/services.xml]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist”。
的错误。
2.7将本项目发布到tomcat下,其中tomcat,在浏览器中输入:http://localhost:8080/xfire/services/MathService?wsdl会得到正确的web服务描述文档。
至此,webservice的服务器端代码开发完毕。
二、客户端开发:
据说客户端开发的方案有很多种,在此本人采用eclipse+xfire插件的方式开发。
1.xfire-eclispe插件安装:
打开eclispe--help--install new software,add Name:(自己填,如xfire);Location:填入网址:http://dist.codehaus.org/xfire/update/ 详细插件安装过程见:http://xfire.codehaus.org/Eclipse+Plugin
2.插件安装成功后:
在eclipse中新建一个Java Project,假设项目名为:xfireTest。
3.在本项目中,new一个XFire--Code generation from WSDL document,点击next,在WSDL URL or path中输入服务器端wsdl的访问网址:本例为http://localhost:8080/xfire/services/MathService?wsdl ,在Output directory中填入:/xfireTest/src,在Package中写入你自己定义的包名:本例中写的是com.hengbao.cilent,点击finish完成。则eclipse会自动生成一个java类和其他的一写文件。本例中生成的java类是在com.hengbao.cilent包下的
public class MathServiceClient {
........
//新增main测试代码
public static void main(String[] args) {
//new一个客户端
MathServiceClient client = new MathServiceClient();
//创建服务
MathServicePortType service = client.getMathServiceHttpPort();
//调用服务
System.out.println(service.add(4, 5));
}
}
其中webservice服务器端,然后运行程序后,在控制台输出“9”,这边明调用web服务成功。
如果在运行客户端程序时,报:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/methods/RequestEntity
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:108)
at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
at org.codehaus.xfire.client.Client.invoke(Client.java:336)
at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
at $Proxy8.hello(Unknown Source)
at life.com.hello.Client.<init>(Client.java:11)
at life.com.hello.Client.main(Client.java:15)
的错误,则表明缺少jar包commons-httpclient-3.0.jar,添加jar后还报:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
at org.apache.commons.httpclient.methods.ExpectContinueMethod.<init>(ExpectContinueMethod.java:93)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.<init>(EntityEnclosingMethod.java:119)
at org.apache.commons.httpclient.methods.PostMethod.<init>(PostMethod.java:106)
at org.codehaus.xfire.transport.http.CommonsHttpMessageSender.open(CommonsHttpMessageSender.java:135)
at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:121)
at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
at org.codehaus.xfire.client.Client.invoke(Client.java:336)
at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
at $Proxy8.hello(Unknown Source)
at life.com.hello.Client.<init>(Client.java:11)
at life.com.hello.Client.main(Client.java:15)
的错误,表明缺少commons-codec-1.3.jar,添加jar包后运行成功,输入“9”。
至此,xifre的webservice应用的服务器端与客户端开发部署完毕。