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 other option

Select the Web service client from the wizard

Select webservice cliet

Provide the service WSDL url in the Service Definition text box and click on finish button.

Enterwsdl into service defination

Web service client stubs will be generated into the package and final folder structure looks below.

Client stubs generated

Write the Client class using the stubs and test the client project.

Write a client


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

* 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) {
} catch (RemoteException e) {


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.


I born in Good cultural place called India. My family is traditional family. We fallow all Indian traditions.

Tagged with: , , , , , , , , , , , , , , ,
Posted in Web Services
4 comments on “Write a Client for web service
  1. […] Click here to know how to write web service client suing java. […]

  2. […] Click here to know how to write web service client suing java. […]

  3. […] Click here to know how to write web service client suing java. […]

  4. […] Example programs for SOAP webservice client […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 679 other followers

February 2013
« Jan   Apr »
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
  • 325,000 hits