公司對外通過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
總結下來,使用第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
搜了半天也沒弄清楚這個類是用來干嘛的,有知道的朋友可能幫忙解答解答,以后有機會再深入研究。
