cxf 异常: No namespace on "html" element. You must send a SOAP request

qozi 2014-12-06 01:11:14
调用web服务http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl 。我用wsdl2java命令生成服务接口和类(无法成功,将wsdl文件拷贝到本地,去掉<s:element ref="s:schema" />,用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 要怎么解决
...全文
10623 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
烽火离别 2018-11-12
  • 打赏
  • 举报
回复
有没有人解决了
「已注销」 2016-07-14
  • 打赏
  • 举报
回复
答案在这里看最后一步http://qqxh.net/779.html
skyjeankk 2015-10-29
  • 打赏
  • 举报
回复
请问一下 WeatherWebService ss=new WeatherWebService(wsdlURL,WeatherWebService.SERVICE_NAME); 这句中的SERVICE_NAME是不是就是WeatherWebService.WeatherWebServiceSoap?? 我用你提供的方法 然后把这里设置成WeatherWebServiceSoap运行后一直报错 Exception in thread "main" javax.xml.ws.WebServiceException: Could not find service named {http://WebXml.com.cn/}WeatherWebServiceSoap in wsdl file:/d:/WeatherWebService.wsdl 请问是怎么解决的,谢谢!!!
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
file:/E:/JAVADOME/weather-webService-client_dome/src/weather.wsdl,
这个文件的路径很重要。
通过这种方式的命令生成的客户端能够得到天气数据
E:\apache-cxf-2.7.15\bin\weather>wsdl2java -frontend jaxws21 -p cn.com.xml -d
e:\ws2400\ -client -autoNameResolution E:\WeatherWS.wsdl

这里有两个特别的地方:
如图所示:
查询天气用自带的客户端就可以测试,不需要任何jar包:

查询结果:
  • 打赏
  • 举报
回复
大神解决了吗?是什么原因?求答案。
miracle_yao 2015-04-23
  • 打赏
  • 举报
回复
你好,我最近也在做这个,用的天气wsdl地址和你一样,遇到的错误也是一样:org.apache.cxf.binding.soap.SoapFault: No namespace on "html" element. You must send a SOAP request.,请问你问题解决了吗?

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧