调用web服务 http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl 。我用wsdl2java命令生成服务接口和类(无法成功,将wsdl文件拷贝到本地,去掉
,用wsdl2java执行本地修改后的wsdl文件成功)。
用下面的方法调用服务,没有问题:
public static void main(String[] args) {
WeatherWS ww = new WeatherWS();
ArrayOfString aos = ww.getWeatherWSSoap().getWeather("深圳", null);
System.out.println(aos.getString());
}
导入cxf的包,继续执行就出现异常:
十二月 06, 2014 12:18:04 下午 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
信息: Creating Service {http://WebXml.com.cn/}WeatherWS from WSDL: file:/E:/JAVADOME/weather-webService-client_dome/src/weather.wsdl
十二月 06, 2014 12:18:10 下午 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
警告: Interceptor for {http://WebXml.com.cn/}WeatherWS#{http://WebXml.com.cn/}getWeather has thrown exception, unwinding now
org.apache.cxf.binding.soap.SoapFault: No namespace on "html" element. You must send a SOAP request.
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.readVersion(ReadHeadersInterceptor.java:112)
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:161)
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:798)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1636)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1525)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1330)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:638)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:137)
at com.sun.proxy.$Proxy44.getWeather(Unknown Source)
at dome.test.T.main(T.java:13)
用同样的方法调用web服务 http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl没有问题。不通的在于,这个地址可以直接用wsdl2java命令生成接口。
如果我要用spring cxf 要怎么解决