How do I develop a client? has been edited by Dan Diephouse (Jun 18, 2007).

(View changes)

Content:

CXF provides you with many options to build clients for your services. This guide is meant to give you a quick overview of those options and help you orient yourself quickly with CXF.

Building Clients

WSDL2Java generated Client

One of the most common scenarios is that where you have a service which you may or not manage and this service has a WSDL. In this case you'll often want to generate a client from the WSDL. This provides you with a strongly typed interface by which to interact with the service. Once you've generated a client, typical usage of it will look like so:

HelloService service = new HelloService();
Hello client = service.getHelloHttpPort();

String result = client.sayHi("Joe");

The WSDL2Java tool will generate a JAX-WS clients from your WSDL. You can run it one of three ways:

For more in depth information read Developing a JAX-WS consumer or see the Hello World demos inside the distribution.

JAX-WS Dispatch APIs

JAX-WS provides "dispatch" mechanism which makes it easy to dynamically invoke services which you have not generated a client for. Using the Dispatch mechanism you can create messages (which can be JAXB objects, Source objects, or a SAAJMessage) and dispatch them to the server. A simple example might look like this:

URL wsdlURL = new URL("http://localhost/hello?wsdl");
Service s = Service.create(new QName("HelloService"), wsdlURL);
Dispatch<Source> disp = service.createDispatch(new QName("HelloPort"), Source.class, Service.Mode.PAYLOAD);

Source request = new StreamSource("<hello/>")
Source response = disp.invoke(request);

NOTE: you can also use dispatches without a WSDL.

For more in depth information see the Hello World demos inside the distribution.

JAX-WS Proxy

Simple Frontend Client

The simple frontend provides a class called ClientProxyFactoryBean which creates a Java proxy with your service interface to talk to your service which was created with the simple frontend. For more information see the Simple Frontend documentation.

Dynamic Client

Reply via email to