View RSS Feed

Spring Framework

Proxying JAX-WS Services in Spring

Rate this Entry
by , 11-28-2011 at 01:25 AM (7099 Views)
I have been exploring JAX-WS services in Spring. In this tip, I will look into proxying JAX-WS services on the client side. Consuming web services with Spring involves client-side proxies in a way similar to how Spring based clients consume other remoting technologies.

Using JaxWsPortProxyFactoryBean is used to wire the Car web service in Spring similar to any other Spring bean. The JaxWsPortProxyFactoryBean is a factory bean that produces a proxy that knows how to talk to a SOAP web service. It will create a proxy implementing the serviceís interface. Therefore with the JaxWsPortProxyFactoryBean you can wire and use a remote web service as if it were any local POJO. If we are configuring the Car web service with the JaxWsPortProxyFactoryBean, it would look like this:

Java Code:
<bean id="carService"
There are several properties of JaxWsPortProxyFactoryBean must be set in order to work. The wsdlDocumentUrl property identifies the location of the remote web serviceís definition file; JaxWsPortProxyFactoryBean uses the WSDL available at that URL to construct a proxy to the service; And the proxy thatís produced by JaxWsPortProxyFactoryBean will implement the CarService interface, as specified by the serviceInterface property. Finallythe remaining three properties can usually be determined by looking at the serviceís WSDL. If the car service looked like this:

Java Code:
<wsdl:definitions targetNamespace=""> 
    <wsdl:service name="carService">
    <wsdl:port name="carServiceHttpPort"
    </wsdl:port> </wsdl:service>
Itís possible for multiple services and/or ports to be defined in the serviceís WSDL. The JaxWsPortProxyFactoryBean requires that the port be specified and service names in the portName and serviceName properties. If you check the <wsdl:port> and <wsdl:service> to determine how to set these properties. The last piece is the namespaceUri property specifies the namespace of the service which will help JaxWsPortProxyFactoryBean locate the service definition in the WSDL. In most cases it is the targetNamespace attribute of the <wsdl:definitions> element.

Submit "Proxying JAX-WS Services in Spring" to Facebook Submit "Proxying JAX-WS Services in Spring" to Digg Submit "Proxying JAX-WS Services in Spring" to Submit "Proxying JAX-WS Services in Spring" to StumbleUpon Submit "Proxying JAX-WS Services in Spring" to Google

Updated 11-30-2011 at 02:36 PM by Spring Framework

Web , Web Service