自动生成的Webservice调用失败并出现解组错误?

时间:2013-07-11 10:22:18

标签: java web-services soap jax-ws cxf

我正在尝试为公共网络服务创建一个测试客户端: 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)

1 个答案:

答案 0 :(得分:1)

解决方案是不删除自动生成的package-info.java。 通常,在创建普通Java项目时,可以省去此工件。但是对于webservices,它包含强制性定义。