Wednesday, July 2, 2008

CXF: X is not a valid SOAP version

Again, a very simple solution, but not at all clear if you're looking at errors in the logs. The basic meaning of this error is that the web service client proxy is attempting to parse the soap envelope from a web service, but cannot find a valid SOAP version in the root element.

The confusing part here is that (at least in my case), it wasn't due to a bad WSDL or bad XML. It was simply that I was pointing my client to the actual WSDL URL instead of the service endpoint. More specifically, I was doing this:

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(UserService.class);
factory.getServiceFactory().setDataBinding(new AegisDatabinding());
factory.setAddress("http://localhost:8080/my-service/MyService?wsdl");
return (MyService) factory.create();

instead of this:

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(UserService.class);
factory.getServiceFactory().setDataBinding(new AegisDatabinding());
factory.setAddress("http://localhost:8080/my-service/MyService");
return (MyService) factory.create();


The short solution: Go check your code for creating your service client. Make sure you're using the location of the service endpoint, NOT the URL for the wsdl itself.

The details:
- CFX 2.1.1
- JBoss 4.0.5GA
- Sun JDK 1.6_6
- Spring 2.5.4

The context:
* Trying to consume a web service using Spring & Apache CXF
* The client throws a SOAPFault whenever it calls the service because it is attempting to run an operation against the URL for the WSDL

No comments: