`
okey9
  • 浏览: 16063 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

CXF SOAP 1.2 SOAP 1.1 问题

    博客分类:
  • CXF
 
阅读更多

在用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 。 
                if (soapVersion == Soap12.getInstance()
                    && version == Soap11.getInstance()) {
                    throw new SoapFault(new Message("INVALID_11_VERSION", LOG, ns, xmlReader.getLocalName()),
                                        Soap11.getInstance().getVersionMismatch());                    
                }
 
回头看看CXF 在初始化的是否可以将 Soap12 设置进去 , ok 。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://cxf.apache.org/jaxws 
          http://cxf.apache.org/schemas/jaxws.xsd">
          	
    <bean id="jaxWsProxyFatory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
        <property name="bindingId" value="http://www.w3.org/2003/05/soap/bindings/HTTP/" />
        <property name="serviceClass" value="net.carefx.cds.v1.services.core.CdsCoreServices" />
        <property name="address" value="http://localhost:8181/cxf/coreServices" />
    </bean>

    <bean id="soapSerivces" class="net.carefx.cds.testtool.proxy.SoapServices">
        <property name="factory" ref="jaxWsProxyFatory" />
    </bean>
    
</beans>  
 


public class SoapServices
{

    private static final Logger logger = new Logger (SoapServices.class.getName ());

    private JaxWsProxyFactoryBean m_factory;

    private CdsCoreServices cdsCoreServices;

    public JaxWsProxyFactoryBean getFactory ()
    {
        return m_factory;
    }

    public void setFactory (JaxWsProxyFactoryBean factory)
    {
        m_factory = factory;
    }

    public CdsCoreServices getCdsCoreServices ()
    {
        if (cdsCoreServices == null)
        {
            cdsCoreServices = (CdsCoreServices) m_factory.create ();
        }
        return cdsCoreServices;
    }

    
}
 
将 bindingId 设置进去就可以了 告诉 cxf 需要用 Soap12 获取返回数据。搞定。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics