Red Hat Training

A Red Hat training course is available for Red Hat Fuse

36.3. Instantiate the WS Client Proxy


The WS client proxy is the most important kind of object in a WS client, because it provides a simple way of invoking operations on a remote Web service. The proxy enables you to access a Web service by invoking methods locally on a Java interface. The methods invoked on the proxy object are then translated into remote procedure calls on the Web service.
You can instantiate a WS client proxy straightforwardly using the jaxws:client element.

Define the WS client in XML

The following Spring XML fragment shows how to instantiate a client proxy bean using the jaxws:client element.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

  <bean id="customerServiceClient"
      init-method="init" destroy-method="destroy">
       <property name="customerService" ref="customerServiceProxy"/>


The jaxws:client element

The jaxws:client element creates a client proxy dynamically (that is, there is no dedicated class that represents a proxy implementation in the Java stub code). The following attributes are used to define the proxy:
The ID that you specify here is entered in the bean registry and can be used to reference the proxy instance from other beans.
The full address of the remote Web service that this proxy connects to.
The fully-qualified class name of the Web service's SEI (you invoke methods on the proxy through the SEI).

Injecting with the proxy reference

To access the proxy instance, simply inject the proxy into one or more other beans defined in XML. Given that the proxy ID has the value, customerServiceProxy, you can inject it into a bean property using the Spring property element, as follows:
<bean ...>
  <property name="customerService" ref="customerServiceProxy"/>
The bean class that is being injected must have a corresponding setCustomerService setter method—for example:
// Java
public class ClientInvoker implements Runnable {
  public void setCustomerService(CustomerService customerService) {
    this.customerService = customerService;