日期:2014-05-20  浏览次数:21054 次

webservice调用问题~
spring集成的cxf调用xfire服务端可以的吗?
服务端是用xfire搭建的,之前客户端也用xfire是可以调用的。
现在的客户端不想使用xfire调用了,也就是用apach的cxf做客户端调用,问题是一直都调用不成功!
配置信息:
<jaxws:client id="client" serviceClass="com.webservice.FilePostService" 
address="http://localhost:8080/DocServer/services/code" />
调用代码:
FilePostService client = (FilePostService)SpringBeanLoader.getSpringBean("client");
System.out.println(client);
String outString = client.sayHellow("test");// 此行报错...
System.out.println(outString);
控制台信息:
2011-6-8 12:07:31 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
信息: Creating Service {http://webservice.com/}FilePostServiceService from class com.webservice.FilePostService
org.apache.cxf.jaxws.JaxWsClientProxy@101e178“这个对象打印”
2011-6-8 12:07:32 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
警告: Interceptor for {http://webservice.com/}FilePostServiceService#{http://webservice.com/}sayHellow has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unexpected wrapper element {http://testService.com}sayHellowResponse found. Expected {http://webservice.com/}sayHellowResponse.
at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:106)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:244)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:729)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2261)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2134)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1988)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:639)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:244)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:516)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
at $Proxy66.sayHellow(Unknown Source)
at org.eredlab.g4.qd.webservice.TestService.main(TestService.java:14)
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Unexpected wrapper element {http://testService.com}sayHellowResponse found. Expected {http://webservice.com/}sayHellowResponse.
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146)
at $Proxy66.sayHellow(Unknown Source)
at org.eredlab.g4.qd.webservice.TestService.main(TestService.java:14)
...


------解决方案--------------------
帮你顶!
------解决方案--------------------
你可以试着把客户端和服务器端的webservice的接口的包路径改成一致的,试试,我先前也碰到到这个问题,不过我的服务器端和客户端都是用的CXF ,你可以试一下
------解决方案--------------------
貌似FilePostService client = (FilePostService)SpringBeanLoader.getSpringBean("client");
不能在TestService.main里用啊 main不会去getSpringBean的
------解决方案--------------------
帮顶,学习。
------解决方案--------------------
用这个试试,
Java code

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(FilePostService .class);
        factory.setAddress("http://localhost:8080/DocServer/services/code");
        FilePostService service= (FilePostService ) factory.create();
        System.out.println("invoke webservice...");
        System.out.println("message context is:" + service.sayHellow("test");