How to create JAX-WS web service client

In this post we will explain how to create JAX WS client stub to make a web service call from JAVA.

First,
Use the below command to create JAVA stub from WSDL.
wsimport -d $PATH_FOR_JAVA_CLIENT $FULL_WSDL_PATH -keep -Xnocompile -verbose
$PATH_FOR_JAVA_CLIENT--Location where the client code will get generated
$FULL_WSDL_PATH--Location of the WSDL 
To run the above command follow the below steps:

1. open cmd prompt.
2. Goto directory "$MiddlewareHome\user_projects\domains\base_domain\bin" .
3. Run "setDomainEnv.cmd" for windows and "setDomainEnv.sh" for Linux
4. Run the below command

wsimport -d C:\wsdl\code http://10.180.90.79:7777/Simple/Porduct/ProductInfo?wsdl -keep -Xnocompile -verbose

Note:
http://10.180.90.79:7777/Simple/Porduct/ProductInfo?wsdl is the dummy webservice that will return dummy product details.

Next,
1. Create new JAVA project say "JAXBClient" in eclipse.
2. Copy entire folder under 'C:\wsdl\code' and paste in SRC folder under JAXBClient project.











3. Create a new com.client.stub.ProductInfo class in same project.


package com.client.stub;
import org.example.productservice.ProductService;
import org.example.productservice.ProductService_Service;
import com.oracle.products.ProductDetail;
public class ProductInfo {
public static void main(String[] args) {
ProductService_Service stub = new ProductService_Service();
ProductService proxy = stub.getProductServiceSOAP();
/*Actual Web service call*/
ProductDetail resp = proxy.getProductInfo(1);
System.out.println("Product Name :" + resp.getProductName());
System.out.println("Product Price :" + resp.getProductPrice());
}
}
On executing the above code, will get below response:

Product Name :Mobile
Product Price :1110.0
Thus we have created JAVA webservice client.
Let me know if you find any issues....

You can download the sample code and WSDL here

Thanks,
Rohan

Popular posts from this blog

JAVA embedding in Oracle SOA 12c

Passing/Receiving HTTP header in SOA BPEL

Integrating Weblogic with IBM MQ over JMS