Tutorial by Vinod Kumat

JAX-WS Web Services stub client wsimport



How to generate the stub client for jax-ws web services by wsimport java utility?
It's so simple, we need WSDL file or service publish then we can use it as end point URL in wsimport tool.

For writing the wsdl client we need to generate all the JAXWS artifacts from the wsdl. Generating the artifacts for Client is same as we generate the artifacts in Tutorial Web Services JDK6 wsimport utility Top-Down Approach..
For generating artifacts you can use wsimport utility of JDK

Generate client side Artifacts
Create a Java project and generate the JAXWS artifacts using wsimport.
e.g:
F:\blogs\JAX-WebServices-Top-Down>wsimport -keep -s src -d bin http://localhost:
8888/GreetingWebService?WSDL
parsing WSDL...

generating code...
Where as I've just created the java project with name JAX-WebServices-Top-Down.

Now our stub class is there as GreetingWebServiceImplService.java.

Adding the client code
Right click on the src located under JAX-WebServices-Top-Down. 
New
Class
Enter the name: GreetingWebServiceClint.java
package: com.vinod.tutorialwebservices.clint

package com.vinod.tutorialwebservices.clint;

import com.vinod.tutorialwebservices.GreetingWebService;
import com.vinod.tutorialwebservices.GreetingWebServiceImplService;

public class GreetingWebServiceClint {

/**
         * Vinod Kumar
* @param args
*/
public static void main(String[] args) {
GreetingWebServiceImplService objGreetingWebServiceImplService =
new GreetingWebServiceImplService();
GreetingWebService obj = objGreetingWebServiceImplService
.getGreetingWebServicePort();
System.out.println(obj.sayWelcome("Vinod Kumar"));
}


}

Out Put:

Vinod Kumar

Project dir will look like as mention below:

JAX-WS, Web Services, stub, client,   wsimport, tutorial, example and code.


Final Words:
Thanks! Hopping, generating the client code web services will work for you as well. Like and share if you like my work. Happy learning and implementation!

No comments:

Post a Comment