Nav
You are viewing an older version of this topic. To go to a different version, use the version menu at the upper-right. +

Using a Web Service Client Directly

This page describes how to use a standalone CXF-generated client with Mule. This approach is different from the outbound router approach, which is typically a more appropriate fit for most applications.

If you plan to connect to an external web service that exposes a WSDL file, the recommended connector to use is the Web Service Consumer.

There are two ways to use CXF clients. First, you can generate a client from WSDL using the CXF WSDL to Java tool. Second, if you’ve built your service via "code-first" methodologies, you can use the service interface to build a client proxy object.

When using a CXF client, it automatically discovers the Mule instance (provided you’re in the same JVM/Classloader) and uses it for your transport. Therefore, if you’ve generated a client from WSDL, invoking a service over Mule can be as simple as the following:


         
      
1
2
3
4
5
6
7
HelloWorldService service = new HelloWorldService();
HelloWorld hello = service.getSoapPort();
 
// Possibly set an alternate request URL:
// ((BindingProvider) greeter).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                       "http://localhost:63081/greeter");
String sayHi = hello.sayHi();

Building a Client Proxy

Following is an example of how to construct a client using the service that was developed in Building Web Services with CXF:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
QName SERVICE_NAME = new QName("http://server.hw.demo/", "HelloWorld");
QName PORT_NAME = new QName("http://server.hw.demo/", "HelloWorldPort");
 
Service service = Service.create(SERVICE_NAME);
 
// Endpoint Address
String endpointAddress = http://localhost:63081/hello";
 
// Add a port to the Service
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
         
HelloWorld hw = service.getPort(HelloWorld.class);
 
System.out.println(hw.sayHi("World"));

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+