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="r4r.in.DataService"/>

<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"/>

</bean>


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="r4r.in.dataClientImpl">

...

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

</bean>

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() {

service.insertData(...);

}}

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in 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!