Hi everyone
Thanks a lot for so much of your help. My problem is sort of solved. 😀
We can consume web services in an application by using #-Link-Snipped-#. I am simplifying the steps and writing them down here
STEP 1: Download separately[or can include them directly form Axis bin/lib folder if Axis is installed] and include following jar files in the CLASSPATH of your Client Class [Class which will consume services]
- axis.jar
- jaxrpc.jar
- saaj.jar
- commons-logging.jar
- commons-discovery.jar
- wsdl4j.jar
[More jars may be required to add depending on the WSDL you might be using.]
STEP 2: Download the WSDL file from Service Provider server's url For.eg. #-Link-Snipped-#
Add File with extension as .wsdl in your project. Let me name above WSDL file as StockQuote.wsdl
STEP 3: Now create stub classes using following command at run time. Go to appropriate structure of your project's folder and enter following command in Command prompt.
java -classpath D:\bin\axis-1_4\lib\axis.jar;D:\bin\axis-1_4\lib\jaxrpc.jar;D:\bin\axis-1_4\lib\saaj.jar;D:\bin\axis-1_4\lib\commons-logging.jar;D:\bin\axis-1_4\lib\commons-discovery.jar;D:\bin\axis-1_4\lib\wsdl4j.jar; org.apache.axis.wsdl.WSDL2Java StockQuote.wsdl
STEP 4: Now you can simply create Client class like following and use the operations specified in your WSDL. You can also pass paramters.
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class TestClient {
public static void main(String [] args) {
try {
String endpoint ="https://www.webservicex.net/stockquote.asmx?WSDL";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName("https://soapinterop.org/", echoString"));
String ret = (String) call.invoke( new Object[] { "Hello!" } );
System.out.println("Sent 'Hello!', got '" + ret + "'");
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
Finally, your work that you want to do using services is done. 😀
For basic flow of Web services , check #-Link-Snipped-#
PS: If any queries, Please ask- I may try to answer.