`

CXF SOAP 1.2 SOAP 1.1 问题

 
阅读更多

在用cxf 做webservice客户端的时候碰到的:

 

javax.xml.ws.soap.SOAPFaultException: A SOAP 1.2 message is not valid when sent to a SOAP 1.1 only endpoint.

 

在网上上找了一些资料但是还是不能解决我的问题,但是还是要感谢下, 不然太不厚道了

 写道
看来是soap协议不匹配
在接口或实现类上声明
@BindingType(value = "http://www.w3.org/2003/05/soap/bindings/HTTP/")
或者
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
注意要引入geronimo-jaxws_2.2_spec-1.0.jar包
生成的wsdl文件我们可以看到
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/
 
在这些前提下 依然返回 同样的错误
于是我试着找源码,发现原来是这里 version 默认的就是 Soap11 instance 。 
Java代码  收藏代码
  1. if (soapVersion == Soap12.getInstance()  
  2.     && version == Soap11.getInstance()) {  
  3.     throw new SoapFault(new Message("INVALID_11_VERSION", LOG, ns, xmlReader.getLocalName()),  
  4.                         Soap11.getInstance().getVersionMismatch());                      
  5. }  
 
回头看看CXF 在初始化的是否可以将 Soap12 设置进去 , ok 。
Java代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="  
  5.           http://www.springframework.org/schema/beans   
  6.           http://www.springframework.org/schema/beans/spring-beans.xsd  
  7.           http://cxf.apache.org/jaxws   
  8.           http://cxf.apache.org/schemas/jaxws.xsd">  
  9.               
  10.     <bean id="jaxWsProxyFatory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">  
  11.         <property name="bindingId" value="http://www.w3.org/2003/05/soap/bindings/HTTP/" />  
  12.         <property name="serviceClass" value="net.carefx.cds.v1.services.core.CdsCoreServices" />  
  13.         <property name="address" value="http://localhost:8181/cxf/coreServices" />  
  14.     </bean>  
  15.   
  16.     <bean id="soapSerivces" class="net.carefx.cds.testtool.proxy.SoapServices">  
  17.         <property name="factory" ref="jaxWsProxyFatory" />  
  18.     </bean>  
  19.       
  20. </beans>    
 
 
Java代码  收藏代码
  1. <span style="font-weight: normal;">  
  2. public class SoapServices  
  3. {  
  4.   
  5.     private static final Logger logger = new Logger (SoapServices.class.getName ());  
  6.   
  7.     private JaxWsProxyFactoryBean m_factory;  
  8.   
  9.     private CdsCoreServices cdsCoreServices;  
  10.   
  11.     public JaxWsProxyFactoryBean getFactory ()  
  12.     {  
  13.         return m_factory;  
  14.     }  
  15.   
  16.     public void setFactory (JaxWsProxyFactoryBean factory)  
  17.     {  
  18.         m_factory = factory;  
  19.     }  
  20.   
  21.     public CdsCoreServices getCdsCoreServices ()  
  22.     {  
  23.         if (cdsCoreServices == null)  
  24.         {  
  25.             cdsCoreServices = (CdsCoreServices) m_factory.create ();  
  26.         }  
  27.         return cdsCoreServices;  
  28.     }  
  29.   
  30.       
  31. }</span>  
 
将 bindingId 设置进去就可以了 告诉 cxf 需要用 Soap12 获取返回数据。搞定。
分享到:
评论
1 楼 zhangy888 2014-04-12  
你好,我正好也遇到了这个问题,按照您的设置有如下几个问题,请帮忙解答一下:
1、net.carefx.cds.testtool.proxy.SoapServices是属于哪个jar包的?
2、SOAPBinding.SOAP12HTTP_BINDING 这个常量设置似乎现有jar包中没有
请帮忙看看,谢谢!

相关推荐

Global site tag (gtag.js) - Google Analytics