JAX-WS Stand Alone Web Services Using JDK1.6 Wsimport Utility Client


In this tutorial we will learn, how to create JAX-WS client by wsimport utility:

Requirements:
1. Java 1.6+
2. Eclipse
3. Windows OS or any.
4. You have already followed my first example for writing the service calss and all from click or video MathService using wsgen utility

Video: 




Open the eclipse
Create the new project as java project.
File > New > Java Project.

Enter the project name: Stand-Alone-Web-Services-Using-JDK1.6-WsImport-Utility-JAXWS-Client
Java project will created in with src and JRE System Library
Note: assuming you have publish the earlier project Math Service and you will able to access the wisdl by any browser, URL > http://localhost:8888/webservice/www.tutorialbyexample.com?wsdl 
and getting the wsdl as response.

if not then follow the previous project first, Click me

Now open the command prompt.
Change the dir: cd C:\workspace\Stand-Alone-Web-Services-Using-JDK1.6-WsImport-Utility-JAXWS-Client 

and type the command:
C:\workspace\Stand-Alone-Web-Services-Using-JDK1.6-WsImport-Utility-JAXWS-Client>wsimport -s src -keep -d class http://localhost:8888/webservice/www.t
utorialbyexample.com?wsdl

Press enter, now your client supporting code will generated, like wise below screen.



Write the client code:

Right click on the src under project Stand-Alone-Web-Services-Using-JDK1.6-WsImport-Utility-JAXWS-Client.

Click New > Class.
Enter the package name:com.tutorialbyexample.mathservice.client
Enter the Class name:MathServiceClient

MathServiceClient.java code will look like:

package com.tutorialbyexample.mathservice.client;

import com.tutorialbyexample.mathservice.MathService;
import com.tutorialbyexample.mathservice.MathServiceService;

public class MathServiceClient {

       public MathServiceClient() {
              // TODO Auto-generated constructor stub
       }

       public static void main(String[] args) {
              //
              MathServiceService objMathServiceService = new MathServiceService();
              MathService objMathService = objMathServiceService.getMathServicePort();
              System.out.println(objMathService.add(10, 40));

       }

}

Hole project directory and file will look like:




Run the MathServiceClient client.
Right click on the MathServiceClient > Run as > Java Application.

Output will appear on the console:
50.0


All done form my end, try at your end. Put your point of view if any.

Have a good day ahead!!

Video link: MathService using wsgen

You can watch this video from Click



No comments:

Post a Comment

Please provide your input, it will honer for me...