Accessing web services using JAX-WS by R4R Team

Accessing web services using JAX-WS:-

Spring provides two factory beans to create JAX-WS web service proxies, namely LocalJaxWsServiceFactoryBean and JaxWsPortProxyFactoryBean. The former can only return a JAX-WS service class for us to work with. The latter is the full-fledged version that can return a proxy that implements our business service interface. In this example we use the latter to create a proxy for the AccountService endpoint .

<bean id="dataWebService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">

<property name="serviceInterface" value=""/>

<property name="wsdlDocumentUrl" value="http://localhost:8888/DataServiceEndpoint?WSDL"/>

<property name="namespaceUri" value="http://example/"/>

<property name="serviceName" value="DataService"/>

<property name="portName" value="DataServiceEndpointPort"/>


Where serviceInterface is our business interface the clients will use. wsdlDocumentUrl is the URL for the WSDL file. Spring needs this a startup time to create the JAX-WS Service. namespaceUri corresponds to the targetNamespace in the .wsdl file. serviceName corresponds to the service name in the .wsdl file. portName corresponds to the port name in the .wsdl file.

Accessing the web service is now very easy as we have a bean factory for it that will expose it as AccountService interface. We can wire this up in Spring:

<bean id="client" class="">


<property name="service" ref="dataWebService"/>


From the client code we can access the web service just as if it was a normal class:

public class DataClientImpl {

private DataService service;

public void setService(DataService service) {

this.service = service;


public void show() {



Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!