Write a Client for web service
Below steps explains how to write a web service client in java using STS IDE.
Step 1: Create a Java project using the steps mentioned here.
Step 2: Generate the stubs for the Java web service using below steps
Mouse Right click on Client project and select New -> Other
Select the Web service client from the wizard
Provide the service WSDL url in the Service Definition text box and click on finish button.
Web service client stubs will be generated into the package and final folder structure looks below.
Write the Client class using the stubs and test the client project.
Use the below sample code to write the client:
package in.malliktalksjava.client;
import java.rmi.RemoteException;
import in.malliktalksjava.Calculator;
import in.malliktalksjava.CalculatorServiceLocator;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;/**
* @author Javatutorials
* @since version 1.0
*
*/
public class SampleWSClient {/**
* @param args
*/
public static void main(String[] args) {SampleWSClient sc = new SampleWSClient();
sc.callCalculatorWebservice();
}/**
* used to call web service
*/
public void callCalculatorWebservice(){String wsdl = “http://localhost:8080/SampleWebService/wsdl/Calculator.wsdl”;
QName queue = new QName(“http://malliktalksjava.in”, “CalculatorService”);try {
//create the servicelocator object
CalculatorServiceLocator calServiceLoc = new CalculatorServiceLocator(wsdl, queue);
//create the service object
Calculator calculator = calServiceLoc.getCalculator();
//call the service methods
System.out.println(“addition result : “+calculator.addition(10, 11));
System.out.println(“division result : “+calculator.division(10, 5));
System.out.println(“multiplication result : “+calculator.multiplication(10, 10));
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
With this your client application is ready to use.
Other Useful links:
Click here to know how to create the web service project.
Click here to know the difference between SOAP and RESTfull web services.
-
February 9, 2013 at 2:29 pm | #1What are the differences between SOAP WS and RESTful WS? « Java Tutorials
-
February 9, 2013 at 2:30 pm | #2Create a java webservice using STS « Java Tutorials
-
February 11, 2013 at 4:16 pm | #3Create a Java web service using top down approch « Java Tutorials
Leave a Reply Cancel reply
Top Posts & Pages
- ListIterator with an example
- Difference between Abstract Class and Interface:
- What is the difference between EAR, JAR and WAR file?
- Difference between Iterator and ListIterator
- SAX Parser Example in JAVA
- Log4j API - Sample Programs
- What are the differences between DispatchAction and LookupDispatchAction in Struts Framework?
- What are the differences between SOAP WS and RESTful WS?
- Replace special characters in a String using java
- Can we declare final method in abstract class?
Blogroll
Top Rated Posts
Most Recent Activities
- Introduction to XSLT
- Types of XML Parsers
- Introduction to XML
- Introduction to Webservice
- Explanation of SOAP WSDL
- Introduction to REST Webservices
- List of Java script MVC Frameworks
- Advantages of Hibernate over jdbc?
- Difference between sorted and ordered collection in hibernate
- Create a Java web service using top down approch
- Write a Client for web service
- Create a java webservice using STS
- Create a Dynamic web project using STS
- What are the differences between SOAP WS and RESTful WS?
- What are the differences between DispatchAction and LookupDispatchAction in Struts Framework?
- Replace special characters in a String using java
- malliktalksjava.in – 2012 in review
- Singleton Design pattern in JAVA
- JBoss Areo Gear – Build Cross-Platform Mobile Apps with Ease
- JBoss Errai – makes rich client easy.
Archive
- April 2013 (7)
- February 2013 (6)
- January 2013 (4)
- December 2012 (5)
- November 2012 (3)
- October 2012 (1)
- September 2012 (6)
- July 2012 (2)
- June 2012 (1)
- February 2012 (1)
- January 2012 (7)
- July 2011 (4)
- January 2011 (1)
- November 2010 (4)
- October 2010 (3)
- September 2010 (13)
- August 2010 (7)
- July 2010 (3)
- June 2010 (2)
- May 2010 (4)
- April 2010 (34)
- July 2009 (9)
Calendar
Mallikarjun Gunda
This is Mallikarjun Gunda, I am working as a software professional. Blogging is my Passion. This blog contains the posts on Java related technologies and programming languages. I am happy to share my knowledge through the blogs.
Blog Stats
- 60,276 hits
IndiBlogger
| malliktalksjava.wordpress.c... |
| 70/100 |




