关于xfire的webservice

huangdh12 2009-12-26 11:07:07
最近用MyEclipse6.5,tomcat5,jdk1.5生成了xfire的webservice 已经生成了wsdl地址
代码如下:


IHelloWorldService.java:
package com.softfz.xfile.test;

public interface IHelloWorldService {

public String sayHello(String name);
}



HelloWorldServiceImpl.java:
package com.softfz.xfile.test;

public class HelloWorldServiceImpl {
public String sayHello(String name){

return "hello,"+name;

}
}

web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

webservice.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>HelloWorldService</name>
<serviceClass>
com.softfz.xfile.test.IHelloWorldService
</serviceClass>
<implementationClass>
com.softfz.xfile.test.HelloWorldServiceImpl
</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service>
</beans>




我的调用程序如下:




package com.softfz.xfile.test;

import java.net.MalformedURLException;

import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

public class HelloWorldClient {

public static void main(String args[]) {

Service srvcModel = new ObjectServiceFactory()

.create(IHelloWorldService.class);

XFireProxyFactory factory = new XFireProxyFactory(XFireFactory

.newInstance().getXFire());

String helloWorldURL = "http://localhost:8080/test/services/HelloWorldService";

try {

IHelloWorldService srvc = (IHelloWorldService) factory.create(

srvcModel, helloWorldURL);

System.out.print(srvc.sayHello("dennis"));

} catch (MalformedURLException e) {

e.printStackTrace();

}

}

}




调用的时候出错如下:

Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Illegal argument invoking 'com.softfz.xfile.test.IHelloWorldService.sayHello(java.lang.String)': object is not an instance of declaring class
org.codehaus.xfire.fault.XFireFault: Illegal argument invoking 'com.softfz.xfile.test.IHelloWorldService.sayHello(java.lang.String)': object is not an instance of declaring class
at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Client.onReceive(Client.java:406)
at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
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 $Proxy0.sayHello(Unknown Source)
at com.softfz.xfile.test.HelloWorldClient.main(HelloWorldClient.java:30)







请问这是啥原因?
生成的wsdl串如下:

<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="http://localhost:8080/test/services/HelloWorldService" xmlns:tns="http://localhost:8080/test/services/HelloWorldService" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://localhost:8080/test/services/HelloWorldService" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <xsd:element name="sayHello">
- <xsd:complexType>
- <xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
- <xsd:element name="sayHelloResponse">
- <xsd:complexType>
- <xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
- <wsdl:message name="sayHelloRequest">
<wsdl:part name="parameters" element="tns:sayHello" />
</wsdl:message>
- <wsdl:message name="sayHelloResponse">
<wsdl:part name="parameters" element="tns:sayHelloResponse" />
</wsdl:message>
- <wsdl:portType name="HelloWorldServicePortType">
- <wsdl:operation name="sayHello">
<wsdl:input name="sayHelloRequest" message="tns:sayHelloRequest" />
<wsdl:output name="sayHelloResponse" message="tns:sayHelloResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="HelloWorldServiceHttpBinding" type="tns:HelloWorldServicePortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="sayHello">
<wsdlsoap:operation soapAction="" />
- <wsdl:input name="sayHelloRequest">
<wsdlsoap:body use="literal" />
</wsdl:input>
- <wsdl:output name="sayHelloResponse">
<wsdlsoap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="HelloWorldService">
- <wsdl:port name="HelloWorldServiceHttpPort" binding="tns:HelloWorldServiceHttpBinding">
<wsdlsoap:address location="http://localhost:8080/test/services/HelloWorldService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>




...全文
467 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hbpad 2010-05-04
  • 打赏
  • 举报
回复
谢谢,原来是这样,粗心所致,习惯啊习惯
williamjywu 2010-04-23
  • 打赏
  • 举报
回复
如需要阅读该回复,请登录或注册CSDN!




huangdh12 2009-12-28
  • 打赏
  • 举报
回复
其实昨天已经找出错误了,是由于配置的原因,实现类没有实现接口导致了,不想就那样结贴。所以留到现在。:)
YOULOVEXIA 2009-12-27
  • 打赏
  • 举报
回复
你再重新检查看看是不是配置文件写错了,或者没有导入所有Xfire包
钱不是问题 2009-12-27
  • 打赏
  • 举报
回复
wsdl能访问说明webservice发布成功了
调用的代码也没有问题
看不出什么问题
lzh_me 2009-12-27
  • 打赏
  • 举报
回复
看看你的webservice.xml有没有正确编译到classes目录下。
这个应该是webservice.xml文件不能加载,看看放的位置是否正确
wqin8 2009-12-27
  • 打赏
  • 举报
回复
帮顶!周末不想看代码!

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧