[WebService] the namespace on the "definitions" element, is not a valid SOAP version

公司对外通过webservice访问别人接口,对方webservice IP地址发生变化,切换过去之后,始终报错,在网上搜索了各种办法之后,暂时总结该问题几种可能解决办法,待真正解决时用的到。

异常详情:

org.apache.cxf.binding.soap.SoapFault: "http://schemas.xmlsoap.org/wsdl/", the namespace on the "definitions" element, is not a valid SOAP version.

javax.xml.ws.WebServiceException: org.apache.cxf.binding.soap.SoapFault: "http://schemas.xmlsoap.org/wsdl/", the namespace on the "definitions" element, is not a valid SOAP version.

        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:154)

可能的几种解决办法:

1. 在编写代码时不要使用factory.create创建service,而使用cxf生成的类创建,具体如下:

// 原先在代码里使用的方法
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(IWebPService.class);
String address1 = "http://192.168.0.121:9090/cloudsun/HelloWorldService?wsdl";
factory.setAddress(address1);
IWebPService ws1 = (IWebPService) factory.create();

// 修改成以下方式初始化
URL url = new URL(address1);
IWebPService ws1 = new (url).getWebPServiceImplPort();
参考:http://www.devexception.com/apache/31208.htm

2. 在调用时设置Address时,在方法1的factory.setAddress后面设置的地址,将?wsdl去掉:

例如:http://服务器IP/UA/TrustAuth?wsdl

修改为:http://服务器IP/UA/TrustAuth

参考:http://www.oschina.net/question/115223_37755

总结下来,使用第1种方法修改,会一劳永逸。

另外补充其他知识:

在搜索过程中有个办法使用

new WebPServiceImplService().getWebPServiceImplPort()生成对象,经查后这个方法有两个多态方法,

public IWebPService getWebPServiceImplPort(WebServiceFeature... features)

public IWebPService getWebPServiceImplPort() {

个人理解下来前面的那个WebServiceFeature是用来改变相应的地址或其他的,可能是理解错误,然后对此做了一些深入的了解:

WebServiceFeature是一个abstract class,其有以下几个子类:

javax.xml.ws.RespectBindingFeature
javax.xml.ws.soap.AddressingFeature
javax.xml.ws.soap.MTOMFeature

搜了半天也没弄清楚这个类是用来干嘛的,有知道的朋友可能帮忙解答解答,以后有机会再深入研究。

参考:http://www.massapi.com/class/ad/AddressingFeature.html

原文地址:https://www.cnblogs.com/garinzhang/p/the_namespace_on_the_definitions_element_is_not_a_valid_SOAP_version.html