Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

CXF provides several ways to invoke services dynamically at runtime - that is, without generating a client from the WSDL. This guide covers usage of the Client interface to interact with a service. Another option you may wish to investigate is the JAX-WS Dispatch API.

Sometimes when you work with web services, you don't want to have to generate a client at build time. Its much more convenient to create a client at runtime and use it dynamically. CXF has a DynamicClientFactory class designed for just this.includes a Client interface which allows you to invoke operations and pass parameters for those operations. For instance:

Code Block
java
java

Client client = ....;
Object[] result = client.invoke("sayHi", "Dan");

There are two ways to create Clients. The first would be through the ClientFactoryBean and JaxWsClientFactoryBean classes. The second is through the DynamicClientFactory. The DynamicClientFactory goes the additional step of generating and compiling JAXB POJOs in the background for use at runtime via reflection. This is most useful when you're using a dynamic language such as Groovy with CXF.

ClientFactoryBeans

TODO

DynamicClientFactory

Let's pretend for a moment that you have a WSDL which defines a single operation "echo" which takes an input of a string and outputs a String. You could use the DynamicClientFactory for it like this:

...