Consume JAX-WS Web Service Using Eclipse

Consume JAX-WS Web Service Using Eclipse explains about how to consume a JAX-WS web Service using in built Eclipse plugin wizard

Note

Thinking that web service is already up and is available on the port 8080 (My server is Tomcat, So Tomcat default port). If not, please check this article Create JAX-WS Web Service Using Eclipse

How to create jax-ws web service client using Eclipse?

Required Libraries

You need to download

  1. JDK 7
  2. Eclipse 3.7
  3. CXF-2.6.1

Steps For Consuming JAX-WS Web Service:

1) Firstly create a Dynamic Web Project (File->New->Dynamic Web Project) named "JAXWSEclipse" according to following screenshot

Create Project Consume Simple JAX-WS Web Service

2) You need to configure the framework, you can have two options CXF or Axis, which we select on step 5

Consume Simple JAX-WS Web Service

3) Right Click on our created project(JAXWSEclipse) (File->New->Other->Web Services->Web Service Client)

Consume Simple JAX-WS Web Service

4) Just Browse your WSDL Location, in our case (http://localhost:8080/CXFTutorial/ChangeStudent?wsdl),You can also change the Web service runtime by clicking Web service runtime link (see next step)

Consume Simple JAX-WS Web Service

5) You can select your Web Service Framework of your choice, You have two options 1) CXF 2)  AXIS which we configured on step 2

Consume Simple JAX-WS Web Service

6) Now click OK button and click Finish

Consume Simple JAX-WS Web Service

7) On below screen shot, you can see all the artifacts are created, you can also see following logs on console

You can see that Eclipse internally using CXF's wsdl2java tool inorder to generate artifacts.

Loading FrontEnd jaxws ...
Loading DataBinding jaxb ...
wsdl2java -client -d C:\Documents and Settings\test\workspace_test\JAXWSEclipse\.cxftmp/src -classdir C:\Documents and Settings\test\workspace_test\JAXWSEclipse\build\classes -p http://student.com/=com.student -impl -validate -exsh false -dns true -dex true -wsdlLocation http://localhost:8080/CXFTutorial/ChangeStudent?wsdl -verbose -defaultValues -fe jaxws -db jaxb -wv 1.1 http://localhost:8080/CXFTutorial/ChangeStudent?wsdl
wsdl2java - Apache CXF 2.6.1

Consume Simple JAX-WS Web Service

8) Create a Main class in order to invoke this service

Main.java

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

// jax-ws 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
Nov 09, 2013 8:36:16 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {http://student.com/}ChangeStudentDetailsImplService from WSDL: http://localhost:8080/CXFTutorial/ChangeStudent?wsdl
Server said: Hello Rockey

 











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