CXF How to set SoapVersion on CXF port without Spring
Asked Answered
O

5

10

I am currently working on a Web Service client using CXF without Spring configuration files.

It works pretty well but I cannot figure out how to set the binding SoapVersion using the Java Api. Using a Spring file this is done as the following:

<jaxws:binding>
    <soap:soapBinding version="1.2"/>
</jaxws:binding>

Do you guys know how to do this in the Java code (on the Port, on the SOAPBinding...)?

Thanks in advance for your help!

EDIT----------------------

I'm still stuck with this problem... I tried to add the SOAPBinding annotation on the interface as suggested in one of the response below but it didn't work... I'm still searching for a way to manually configure my PortType / Binding / Bus to use Soap 1.2...

Any ideas?

EDIT----------------------

Problem solved! Actually I answered my own question: see below...

Thanks!

Omasum answered 22/11, 2010 at 17:11 Comment(0)
O
14

Ok I answer again to my own question to share the solution. With the help of the guys from the CXF mailing list I found a solution that works for me. There is actually 2 ways to solve the problem. Here is the explanation:

The problem came from the way I was building my CXF Service.

The first solution is to specify the WSDL location at Service creation time:

// Create the service
Service service = Service.create(urlToWsdl, serviceQName);
// Access the port
return service.getPort(serviceQName, portTypeClass);

This solved the problem but I didn't want to have that link to the WSDL, so here is the second solution that gets rid of this link:

// Create the service
Service service = Service.create(serviceQName);
// Add a Port to the service and specify the SOAP 1.2 binding
service.addPort(serviceQName, javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING, wsUrl);
// Access the port
return service.getPort(serviceQName, portTypeClass);

In my project we decided to choose the second solution.

Hope this helps!

Omasum answered 24/1, 2011 at 9:55 Comment(1)
How can i do it using cxf? I'm creating service like this Object implementor = new DiscoveryLookupPortImpl(); Endpoint.publish("udp://239.255.255.250:3702", implementor); where public class DiscoveryLookupPortImpl implements DiscoveryLookupPortWabble
I
7

Easiest is probably to just stick an annotation on the interface of:

@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
Inkblot answered 22/11, 2010 at 17:20 Comment(6)
@reef: What are you getting the description of the interface from?Marchioness
@Donal Fellows It's the result of a wsdl2java tool execution. It's basically one of my project dependencies.Omasum
@reef: That's the sort of thing that it's really useful to put in a question. Is there some way to make the WSDL you're converting from say that it wants SOAP 1.2? (I've not tinkered with that part of SOAP for a while so I forget the details.) If there is, surely that's where the info should actually go? After all, if that's what the service requires then that's what it should ask for…Marchioness
@Donal Fellows Actually I figured out the issue by configuring the server to ask for SOAP 1.2 messages. Using on the client the Soap 1.2 Porttype it works pretty well.Omasum
@reef: Cool. You should mention what you did as an answer so that we can give you some votes. (Really! Answering your own questions is quite OK when you've got a real answer that can help others.)Marchioness
@Daniel Kulp: Adding an annotation on the interface didn't work either... I still have my SOAP message with version 1.1 (ie: xmlns:soap="schemas.xmlsoap.org/soap/envelope/").Omasum
H
2

if you are using cxf client , you can use following way. Also it can bind more than one wsdl.

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(WebServiceClass);
        BindingConfiguration config = new BindingConfiguration() {

    @Override
    public String getBindingId() {
            // TODO Auto-generated method stub
            return "http://www.w3.org/2003/05/soap/bindings/HTTP/";//SOAPVersion.SOAP_12.httpBindingId
    }
    };
    factory.setBindingConfig(config);
Hour answered 13/10, 2016 at 7:8 Comment(0)
O
0

As suggested by Donal Fellows I answer to my own question ;)

Actually the issue was linked to the Soap version the server can handle. On the client side I do not need to specify that I want to use Soap 1.2, it seems it's sufficient to have the PortType in the WSDL file configured to Soap 1.2. But on the server side I need to explicitly tell which Soap version I want. On the server side I still use the "Spring-mode" for CXF configuration thus I just added the following in the XML configuration file:

<jaxws:binding>
    <soap:soapBinding version="1.2"/>
</jaxws:binding>

That's all folks! Thanks for your time and help!

EDIT --------------------------------

Actually this solution does not work now that we contact a server we do not manage.... We are still stuck with our problem here....

Omasum answered 25/11, 2010 at 16:20 Comment(1)
Ok, this solution worked as I did have access to both client and server side. Now that I have to contact a server I don't manage this does not work. Do you guys know how to set the SOAP version without Spring configuration?Omasum
E
0

Old thread. I thought I'd post a solution that worked for me. In the cxf-beans.xml file, I changed the endpointName="tns:MR_ServerSoap12" from endpointName="tns:MR_ServerSoap". Note that the endpoint name will have its own name in your wsdl. Use that name.

Encaustic answered 26/4, 2016 at 18:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.