Tuesday, April 24, 2012

Step by step guide to consume a web service

Consuming a web service is very easy all you need to have a WSDL url and an IDE i.e Eclipse for creating web service client. Provide WSDL url and download the stubs. Below mentioned files are automatically generated by WSDL.

Lets create a simple web service client.

Step by step process to create web service client. Please see the screen shots below.





Add project name, lets say SimpleWebserviceClient




Now creating a client.






Add WDSL URL http://localhost:8080/SimpleWebservice/hellows?wsdl

Step by step guide to publish a simple Hello World web service using tomcat





After clicking Finish, you will see stubs are downloaded. You should able to see below mentioned sample classes.


Example : 
HelloWS.java (exposed interface)
HelloWSImplService.java (generated class)

Now we will creata TestClient.java
/* TestClient.java */

package com.javaxp;

public class TestClient {

public static void main(String[] args) {

HelloWSImplService service = new HelloWSImplService();

HelloWS helloWS = service.getHelloWSImplPort();
System.out.println(helloWS.sayHello("Madan"));
}

}


Output