Apache CXF:SOAP 1.2消息在发送到仅限SOAP 1.1的端点时无效

Aur*_*ere 2 java soap web-services cxf

首先,我知道关于这个话题已经有一些问题但是没有一个问题解决了我的问题(或者我太愚蠢而无法理解它们,这也是一种可能性).

所以,我有一个WSDL.从WSDL我使用Eclipse CXF插件生成了一个Java客户端.现在我这样做:

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(MyServiceInterface.class);
factory.setAddress("myEndpoint");
List<Interceptor<? extends Message>> interceptors = new ArrayList<Interceptor<? extends Message>>();
interceptors.add(new HeaderOutInterceptor());
factory.setOutInterceptors(interceptors);

MyServiceInterface service = (MyServiceInterface) factory.create();
Run Code Online (Sandbox Code Playgroud)

拦截器只为我通过客户端发送的请求添加标头:

message.put(Message.CONTENT_TYPE, "application/soap+xml");
Run Code Online (Sandbox Code Playgroud)

我手动添加这个,因为默认情况下内容类型是text/xml,我得到415错误.

问题是,使用此配置,我得到以下异常:

org.apache.cxf.binding.soap.SoapFault: A SOAP 1.2 message is not valid when sent to a SOAP 1.1 only endpoint.
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:178)
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:69)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
Run Code Online (Sandbox Code Playgroud)

我已经尝试将此注释添加到生成的客户端界面:

@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
Run Code Online (Sandbox Code Playgroud)

但没有改变.有谁能够帮我?

编辑

我在类路径下添加了一个cxf.xml文件.这是内容:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://cxf.apache.org/bindings/soap 
       http://cxf.apache.org/schemas/configuration/soap.xsd
       http://cxf.apache.org/jaxws 
       http://cxf.apache.org/schemas/jaxws.xsd">

<jaxws:endpoint serviceName="ClabService" endpointName="ClabServicePort">
    <jaxws:binding>
        <soap:soapBinding version="1.2" mtomEnabled="true" />
    </jaxws:binding>
</jaxws:endpoint>

</beans>
Run Code Online (Sandbox Code Playgroud)

但是,现在我得到了这个例外:

Exception in thread "main" java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.jaxws.EndpointImpl---51955260': Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: serviceClass must be set to a valid service interface or class
Run Code Online (Sandbox Code Playgroud)

我试图在出厂配置期间添加它:

factory.setServiceClass(MyServiceInterface_Service.class);
Run Code Online (Sandbox Code Playgroud)

但没有改变.

Vij*_*ade 11

您可以使用JaxWsClientFactoryBean来创建客户端.它可以选择setBinding到Soap 1.2.

JaxWsClientFactoryBean factory = new JaxWsClientFactoryBean();
factory.setServiceClass(MyServiceInterface.class);
factory.setAddress("myEndpoint");
List<Interceptor<? extends Message>> interceptors = new ArrayList<Interceptor<? extends Message>>();
interceptors.add(new HeaderOutInterceptor());
factory.setOutInterceptors(interceptors);
factory.setBindingId("http://www.w3.org/2003/05/soap/bindings/HTTP/");//soap 1.2
MyServiceInterface service = (MyServiceInterface) factory.create();
Run Code Online (Sandbox Code Playgroud)

  • 可以在`javax.xml.ws.soap.SOAPBinding`接口中找到可用的绑定 (4认同)