Skip to content

Guide to wsimport

September 17, 2012

What is wsimport?

wsimport is a command/tool that ships along with JDK 1.6 and later which when provided with the location of a WSDL file can generate Java files to call the web services described by that WSDL file.

Verify wsimport is installed:

$ where wsimport

$ which wsimport

Steps on how to Generate java code:

  1. Get either the URL to the WSDL file or the actual file itself.
  2. Open a Command Prompt/Terminal and navigate to where you want the files to be dropped into.
  3. Generate Java Code
    $ wsimport -keep {url-or-path-to-wsdl}
    • Note 1: the “-keep” portion of the command is used when you want to keep the .java files generated by the wsimport tool. Usually the wsimport tool generates the java files then compiles them into .class files and removes them.
    • Note 2: If you would like to get rid of the generaeted .class files execute:
      $ del /s  *.class
  4. Modify the package values in the generate java classes as necessary in your project

Description of generated files

  • The contents of the generated folder will be Request and Response objects as well as an ObjectFactory class and 2 other classes, one of which will be the name of the service ({name-of-service}.java) which I will call the Service class and the other of which will contain the name of the servcie with “Soap” appended to it ({name-of-service} which I will call the SoapService class.
  • The can be used to create complex request objects (requests than one request object) that

Steps on how to use the Generated Java code:

  1. Create a Service object with the default constructor.
  2. Create a SoapService object by using the get service method  in the Service object.
  3. If needed by the service you’re calling, create a Request object using the ObjectFactory class.
  4. Use the SoapService object you created to call the actual soap service.
    • Pass in the Request object if needed or pass in a String or Integer (whatever the function requires)


The website has a few SOAP servcies I’ve used to test SOAP clients and such. I am going to be using one of their services to demonstrate how you can use wsimport.

Location of service:
Location of WSDL:
Code to generate Java:
$ cd /path/to/project/src
$ wsimport -keep
Test Code to use generated files:
package project;

import net.webservicex.Whois;
import net.webservicex.WhoisSoap;

public class main {
    public static void main(String[] args) {
        Whois whois = new Whois();
        WhoisSoap whoisSoap = whois.getWhoisSoap();
        String response = whoisSoap.getWhoIS("");

From → Guide

One Comment
  1. Nice site. I’m jealous. Save the ferrets!!

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: