In a previous article, we have created SOAP Web service with JAX-WS API. Next part is how can we consume it in Java, How to create stub files or client in Java, Today we will cover steps to create stub files in java using internal JDK tool called wsimport.

wsimport tool is used to generate JAX-WS portable artifacts. For example :

  • Service Endpoint Interface (SEI)
  • Service
  • Exception class mapped from wsdl:fault
  • Async Reponse Bean derived from response wsdl:message
  • JAXB generated value types

wsimport tool comes within JDK itself, We can found at {JAVA_HOME}/bin/wsimport.exe

Syntax :

wsimport [options] <wsdl>

Let’s understand different options available while invoking a command.

Options :

  1. -d directory

    -d option is used to specifies where to place generated output files. For example :

    wsimport -d “D:\codeNuclear” <wsdl>
  2. -b path

    Specifies external JAX-WS or JAXB binding files. Multiple JAX-WS and JAXB binding files can be specified with the -b option. You can use these files to customize package names, bean names, and so on.

  3. -help

    Displays a help message for the wsimport command.

  4. -httpproxy: host:portp

    Specifies an HTTP proxy server. The default is 8080.

  5. -keep

    Keeps generated files.

  6. -p name

    Specifies a target package name to override the WSDL and schema binding customizations, and the default algorithm defined in the specification.

    wsimport -p com.codenuclear <wsdl>
  7. -verbose

    Displays compiler messages.

  8. -version

    Prints release information.

Example :

Let’s take example with wsdl[http://localhost:8080/StockWebservice/stockendpoint?wsdl] we created in previous article.

wsimport -keep http://localhost:8080/StockWebservice/stockendpoint?wsdl

With the command, listed Java classes have been created. Here as our method getStockPrice(String stockName) having input param is as a String hence no other Request and Response POJO class created.

  1. StockEndPoint.java
  2. StockEndPointImplService.java

Let’s write client code with help of above generated classes.



That’s all for SOAP Web Service client with wsimport, Hope you like it, Keep reading and sharing !! :)

Leave a Reply

Your email address will not be published. Required fields are marked *