Search code examples
wcfweb-servicessoapcxf

How do I consume a WCF Soap 1.2 Web Service using a CXF Web Service Client?


Does anyone know the trick to calling a WCF (Soap 1.2) web service from CXF?

I've been trying to get a basic hello world client working for a while now and I've had no luck.

It works fine with Soap 1.1.

When I print out the SoapBinding the client is using it's using soap 1.1 even though it's a soap 1.2 service when I set the soap binding manually to 1.2 it freezes up when you make the web service call and eventually dies with a socket timeout exception (Read timed out).

public static void main(String[] args) {
        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(ITest.class);
        factory.setAddress("http://localhost/Test/test.svc");
        final Soap12 soap12 = Soap12.getInstance();

        BindingConfiguration config = new BindingConfiguration() {

            @Override
            public String getBindingId() {
                return soap12.getBindingId();
            }
        };
        factory.setBindingConfig(config);
        factory.setBindingId(soap12.getBindingId());        
        ITest service = (ITest) factory.create();

        org.apache.cxf.endpoint.Client client = ClientProxy.getClient(service);
        client.getRequestContext().put("ContentType", "text/xml; charset=utf-8");
        SoapBinding binding = (SoapBinding) client.getEndpoint().getBinding();
        System.out.println("[" + binding.getSoapVersion() + "]");
        System.out.println(service.test("World"));
    }

This is the soap request that gets sent to the WCF Service.

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<Test xmlns="http://tempuri.org/" xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/">
<s>World</s>
</Test>
</soap:Body>
</soap:Envelope>

Solution

  • I actually found out CXF doesn't support calling a Soap 1.2 WCF Service that uses wsHttpBinding. I switched the WCF web service to use BasicHttpBinding and It works now.