Joined: 16/02/2012 12:59:39
This tutorial explains the process of creating the webservice client for a weather application. I am using axis 2 for this purpose and soap UI for testing the web services. please put all the library files from axis into the lib folder of your project and add it to the build path. I am using Eclispe IDE for this purpose.
I am using the following uri for the WSDL file I found on the internet:http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl to generate the java stub files. To generate the stub files go to you command prompt and go to your axis 2.0 bin folder in my case it is :C:\Users\sagar\Desktop\JAVA Training\axis2-1.6.1-bin\axis2-1.6.1\bin. you need to run the wsdl2java.bat file to generate the java files from the wsdl file .use this command to generate the java class file :
This will create two java class file into the weather folder inside the bin directory of your axis 2.
Now create a package called "com.cdyne.ws.weatherws" inside the src folder of your project folder and copy these two java files inside the package.
Now we will create a .JAR file out of these java classes and add it into the lib folder of our project. select these two java class files right click and export jar and name it as anything , in my case i named it as "weather.jar"
Now copy the jar file into the lib folder of your project and and add it to the build path too.
Now we will be using the jar file to access the web services methods and you can delete the two java classes files we copied as they already are in the jar files.
.I am writing a test program to test my web service now. I will write a "WeatherTest.java" file to test it.before writing it you can find out what the wsdl file is taking as request and what response it is giving back by simply copying the wsdl link"http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl" into the SoapUI software.After i found out my requests and response i wrote my test program as follows:
Now you are all set. Run your program and enjoy your weather. the output i got is :