Step 1:- First download Apache Axis latest version from below site
https://axis.apache.org/axis2/java/core/download.html
![Image_1](https://shdhumale.files.wordpress.com/2016/05/image_1.png?w=680)
Step 2- Open Eclipse I am using Eclipse Java EE Luna 4.4.1
![Image_2](https://shdhumale.files.wordpress.com/2016/05/image_2.png?w=680)
Step -3- Go to window->preference->Web Service and click Axis Preference and set the path where we had extracted our download from
https://axis.apache.org/axis2/java/core/download.html and click Apply and ok button.
https://axis.apache.org/axis2/java/core/download.html and click Apply and ok button.
![Image_3](https://shdhumale.files.wordpress.com/2016/05/image_3.png?w=680)
Step -3 Create Dynamic Web Project and import our class which we want to expose as a webservice.
File -> New -> Web Project
File -> New -> Web Project
![Image_4](https://shdhumale.files.wordpress.com/2016/05/image_4.png)
Give name of the project and set the configuration as shown in the below figure.
![Image_5](https://shdhumale.files.wordpress.com/2016/05/image_5.png)
Make sure to click on Modify button of custom configuration and click on Axis as shown in below image and click Ok
![Image_6](https://shdhumale.files.wordpress.com/2016/05/image_6.png?w=680)
Click on Finish Button
Step -4 Create New Class as shown in belwo image
![Image_7](https://shdhumale.files.wordpress.com/2016/05/image_7.png?w=680)
public class TestSiddhu {
public String add (String i,String j)
{
int k = Integer.parseInt(i) + Integer.parseInt(j);
System.out.println("k--------"+k);
return ""+k;
}
/*public static void main(String args[])
{
TestSiddhu objV = new TestSiddhu();
objV.add("4", "5");
}*/
{
TestSiddhu objV = new TestSiddhu();
objV.add("4", "5");
}*/
}
![Image_8](https://shdhumale.files.wordpress.com/2016/05/image_8.png?w=680)
Step -5 Lets assume we want our add method to be exposed as web service
Riht click --> JAVA Class --> New --> Other and select Web Service
Riht click --> JAVA Class --> New --> Other and select Web Service
![Image_9](https://shdhumale.files.wordpress.com/2016/05/image_9.png?w=680)
![Image_10](https://shdhumale.files.wordpress.com/2016/05/image_10.png)
click Next and follow below sequence.
![Image_11](https://shdhumale.files.wordpress.com/2016/05/image_11.png)
Click on Apache Axis
![Image_12](https://shdhumale.files.wordpress.com/2016/05/image_12.png?w=680)
![Image_13](https://shdhumale.files.wordpress.com/2016/05/image_13.png)
Click on start Button
![Image_14](https://shdhumale.files.wordpress.com/2016/05/image_14.png)
![Image_15](https://shdhumale.files.wordpress.com/2016/05/image_15.png)
Click Finish
![Image_16](https://shdhumale.files.wordpress.com/2016/05/image_16.png)
Note: Close your Tomcat and run your created application on tomcat once again
![Image_17](https://shdhumale.files.wordpress.com/2016/05/image_17.png?w=680)
Click on Next button
![Image_18](https://shdhumale.files.wordpress.com/2016/05/image_18.png)
Click finish
![Image_19](https://shdhumale.files.wordpress.com/2016/05/image_19.png?w=680)
You will be able to see this screen
![Image_20](https://shdhumale.files.wordpress.com/2016/05/image_20.png?w=680)
click on Service and you will get this page
![Image_21](https://shdhumale.files.wordpress.com/2016/05/image_21.png?w=680)
click on siddhu and see you are able to access WSDL file as shown below
![Image_22](https://shdhumale.files.wordpress.com/2016/05/image_22.png?w=680)
Step 5- Now lets create Client that will consume our Exposed WSDL.
Create and new Dynamic web project with name TestSiddhuAxisWebserviceClient similar to our TestSiddhuAxisWebserviceServer Project
![Image_23](https://shdhumale.files.wordpress.com/2016/05/image_23.png)
![Image_24](https://shdhumale.files.wordpress.com/2016/05/image_24.png)
![Image_25](https://shdhumale.files.wordpress.com/2016/05/image_25.png)
http://localhost:8181/TestSiddhuAxisWebserviceServer/services/TestSiddhu?wsdl
![Image_26](https://shdhumale.files.wordpress.com/2016/05/image_26.png?w=680)
clieck on next
![Image_27](https://shdhumale.files.wordpress.com/2016/05/image_27.png?w=680)
Click on finish and you will see two class 1- *Stub and 1- *Handler created
Lets create our main method in client code and consume the same.
package org.apache.ws.axis2;
public class SiddhuMainClass {
public static void main(String args[])
{
try {
TestSiddhuStub obTestSiddhuStub = new TestSiddhuStub();
org.apache.ws.axis2.TestSiddhuStub.Add objAdd = new org.apache.ws.axis2.TestSiddhuStub.Add();
objAdd.setI("3");
objAdd.setJ("4");
obTestSiddhuStub.add(objAdd);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
{
try {
TestSiddhuStub obTestSiddhuStub = new TestSiddhuStub();
org.apache.ws.axis2.TestSiddhuStub.Add objAdd = new org.apache.ws.axis2.TestSiddhuStub.Add();
objAdd.setI("3");
objAdd.setJ("4");
obTestSiddhuStub.add(objAdd);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and Execute the programe
![Image_28](https://shdhumale.files.wordpress.com/2016/05/image_28.png?w=680)
Note :- You can use the same concept for creating and cosming Apache CXF Web service. Only need to download Apache CXF JAR and add the path to window-->preference-->Web Service of Eclipse
No comments:
Post a Comment