CXF客户端调用报错:org.apache.cxf.interceptor.Fault: Unmarshalling Error: 意外的元素 (uri:"http://tempuri.org/", local:"SendSMSResult")。所需元素为<{}SendSMSResult>
org.apache.cxf.interceptor.Fault: Unmarshalling Error: 意外的元素 (uri:"http://tempuri.org/", local:"SendSMSResult")。所需元素为<{}SendSMSResult>
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:808) ~[cxf-rt-databinding-jaxb-2.7.6.jar:2.7.6]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:629) ~[cxf-rt-databinding-jaxb-2.7.6.jar:2.7.6]
at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:157) ~[cxf-rt-databinding-jaxb-2.7.6.jar:2.7.6]
at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:103) ~[cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:811) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1590) [cxf-rt-transports-http-2.7.6.jar:2.7.6]
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1486) [cxf-rt-transports-http-2.7.6.jar:2.7.6]
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1305) [cxf-rt-transports-http-2.7.6.jar:2.7.6]
at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:50) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:223) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:623) [cxf-rt-transports-http-2.7.6.jar:2.7.6]
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:541) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:474) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:377) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:330) [cxf-api-2.7.6.jar:2.7.6]
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) [cxf-rt-frontend-simple-2.7.6.jar:2.7.6]
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134) [cxf-rt-frontend-jaxws-2.7.6.jar:2.7.6]
at com.sun.proxy.$Proxy315.sendSMS(Unknown Source) [na:na]
Caused by: javax.xml.bind.UnmarshalException: null
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:483) ~[com.sun.xml.bind.jaxb-impl_2.2.jar:2.2.7-b63]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:417) ~[com.sun.xml.bind.jaxb-impl_2.2.jar:2.2.7-b63]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:394) ~[com.sun.xml.bind.jaxb-impl_2.2.jar:2.2.7-b63]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:769) ~[cxf-rt-databinding-jaxb-2.7.6.jar:2.7.6]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:94) ~[cxf-rt-databinding-jaxb-2.7.6.jar:2.7.6]
at org.apache.cxf.jaxb.JAXBEncoderDecoder$1.run(JAXBEncoderDecoder.java:797) ~[cxf-rt-databinding-jaxb-2.7.6.jar:2.7.6]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_51]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:795) ~[cxf-rt-databinding-jaxb-2.7.6.jar:2.7.6]
... 27 common frames omitted
研究了大半个晚上,查看百度、google都说是命名空间没加的原因导致,最后发现并不是这样的,反而是多加了命名空间导致了错误。
原因是因为接口类名已经添加了命名空间,以及返回的类对象中也指定了命名空间,多处指定命名空间导致找不到是哪一个了。所以报错。
原代码接口:
@WebResult(name = "SendSMSResult", targetNamespace = "http://tempuri.org/")
@RequestWrapper(localName = "SendSMS", targetNamespace = "http://tempuri.org/", className = "com.comtop.lcam.fwms.common.mobilemessage.sz.client.SendSMS")
@WebMethod(operationName = "SendSMSRet ", action = "http://tempuri.org/sendSMS")
@ResponseWrapper(localName = "SendSMSResponse", targetNamespace = "http://tempuri.org/", className = "com.comtop.lcam.fwms.common.mobilemessage.sz.client.SendSMSResponse")
public com.comtop.lcam.fwms.common.mobilemessage.sz.client.SendSMSRet sendSMS();
修改后:
@WebResult(name = "SendSMSResult", targetNamespace = "http://tempuri.org/")
@RequestWrapper(localName = "SendSMS", targetNamespace = "http://tempuri.org/", className = "com.comtop.lcam.fwms.common.mobilemessage.sz.client.SendSMS")
@WebMethod
@ResponseWrapper(localName = "SendSMSResponse", targetNamespace = "http://tempuri.org/", className = "com.comtop.lcam.fwms.common.mobilemessage.sz.client.SendSMSResponse")
public com.comtop.lcam.fwms.common.mobilemessage.sz.client.SendSMSRet sendSMS();
;