Java wsimport Tool Example

Java wsimport Example explains about generating Java Code From A WSDL Document, So that Client Can Invoke/Consume The Service

I am showing here, an example of generating java code from WSDL document using wsimport tool.

You can also use CXF Client , if you need more custom features like adding logging,interceptor etc.

Reference -> http://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html

For deploying the service, you can follow this tutorial CXF Web Service Tutorial. After the deployment you can access the url

http://localhost:8080/CXFTutorial/ChangeStudent?wsdl

Required Libraries

You need to download

  1. JDK 7 (wsimport tool is available from jdk5 onwards)

Now I am invoking wsimport tool from console like following

C:\>wsimport -keep http://localhost:8080/CXFTutorial/ChangeStudent?wsdl
parsing WSDL...



Generating code...


Compiling code...

You can view the generated code on below screenshot

wsimport Example

Run Client

package com.client;

import com.student.ChangeStudentDetails;
import com.student.ChangeStudentDetailsImplService;
import com.student.Student;

// wsimport example

public class Main {

 
public static void main(String[] args) {
   
ChangeStudentDetailsImplService service = new ChangeStudentDetailsImplService();
    ChangeStudentDetails changeStudentDetailsImplPort = service.getChangeStudentDetailsImplPort
();
    Student student =
new Student();
    student.setName
("Rockey");
    Student changeName = changeStudentDetailsImplPort.changeName
(student);
    System.out.println
("Server said: " + changeName.getName());
 
}

}
Output
Server said: Hello Rockey

 






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