我正在尝试通过公共Web服务创建测试客户端:
http://www.webservicex.com/currencyconvertor.asmx?WSDL
将Eclipse与CXF 2.x配合使用可自动生成WS Client。到目前为止看起来还不错,但是在执行时我只会收到以下错误。
发生这种情况时,我将调用webservice方法conversionRate
,该方法也会自动生成,如下所示:
@WebService(targetNamespace = "http://www.webserviceX.NET/", name = "CurrencyConvertorSoap")
@XmlSeeAlso({ObjectFactory.class})
public interface CurrencyConvertorSoap {
@WebResult(name = "ConversionRateResult", targetNamespace = "http://www.webserviceX.NET/")
@RequestWrapper(localName = "ConversionRate", targetNamespace = "http://www.webserviceX.NET/", className = "ConversionRate")
@WebMethod(operationName = "ConversionRate", action = "http://www.webserviceX.NET/ConversionRate")
@ResponseWrapper(localName = "ConversionRateResponse", targetNamespace = "http://www.webserviceX.NET/", className = "ConversionRateResponse")
public double conversionRate(
@WebParam(name = "FromCurrency", targetNamespace = "http://www.webserviceX.NET/")
Currency fromCurrency,
@WebParam(name = "ToCurrency", targetNamespace = "http://www.webserviceX.NET/")
Currency toCurrency
);
}
我如何找出错误的来源?这里可能出什么问题了?
错误:
Warnung: Interceptor for {http://www.webserviceX.NET/}CurrencyConvertor#{http://www.webserviceX.NET/}ConversionRate has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unmarshalling Error: unerwartetes Element (URI:"http://www.webserviceX.NET/", lokal:"ConversionRateResult"). Erwartete Elemente sind <{}ConversionRateResult>
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:808)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:629)
at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:157)
at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:103)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:800)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1592)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1490)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1309)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:622)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:133)
at $Proxy35.conversionRate(Unknown Source)
at CurrencyConvertorSoap_CurrencyConvertorSoap_Client.main(CurrencyConvertorSoap_CurrencyConvertorSoap_Client.java:50)
最佳答案
解决方案是不要删除自动生成的package-info.java
。
通常,在创建普通的Java项目时,可以节省该工件。但是对于Web服务,它包含强制性定义。