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 。 
                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 获取返回数据。搞定。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值