首先,我知道关于这个主题已经有一些关于SO的问题,但是没有一个问题解决了我的问题(或者我太愚蠢而无法理解它们,这也是可能的。)
所以,我有一个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();
拦截器只为我通过客户端发送的请求添加标头:
message.put(Message.CONTENT_TYPE, "application/soap+xml");
我手动添加此内容,因为默认情况下内容类型为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)
我已尝试将此注释添加到生成的客户端界面:
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
但没有改变。有人能帮助我吗?
修改
我在类路径下添加了一个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>
然而,现在我得到了这个例外:
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
我试图在出厂配置期间添加它:
factory.setServiceClass(MyServiceInterface_Service.class);
但没有改变。
答案 0 :(得分: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();
答案 1 :(得分:1)
geg已经说过了,我只是想让它更加明显:
import javax.xml.ws.soap.SOAPBinding;
...
factory.setBindingId(SOAPBinding.SOAP12HTTP_BINDING);