Eclipse – Generate a SOAP client from WSDL

This tutorial provides a step by step guide on how to generate a SOAP client from WSDL using Eclipse.

1. Create a stand-alone project

If you’re going to generate the SOAP client classes inside an existing project, then you can skip this step.

If you’re starting from scratch, then create a new standard stand-alone project and name it as WebServiceClient, we will later use this project when generating our SOAP client classes.

2. Create a new web service client

Select the project that we create in step 1 by clicking on the project name. Then go to File -> New -> Other and search for “Web Service Client”:

Soap service client

Click Next.

In the next page, put the URL of your WSDL, if you have the WSDL locally on your machine, you can copy it under your project and locate it using browse.

For testing purposes, we’re going to use a sample online calculator service that is located under “http://www.dneonline.com/calculator.asmx?wsdl“.

Eclipse browse wsdl

Keep all the settings as is then click Finish.

3. Client.java

After clicking on “Finish”, the client classes will be generated under your selected project using their own package as the following:

Eclipse generated soap client classes

The last step is to consume the web service using these generated classes, in order to do so, we create a main class called Client.java which simply calls the add() function of the calculator service in order to add 2 numbers:

As noticed, to consume a SOAP service, follow the below order:

  • Create an instance of the Locator.
  • Get an instance of the Stub through the Locator.
  • Finally, call the requested method through the Stub.

Hussein Terek

Founder of programmergate.com, I have a passion in software engineering and everything related to java environment.

You may also like...

Leave a Reply

avatar