Friday, April 13, 2012

Creating Bottom Up WebServices

Web services can be created using two methods: top-down development and bottom-up development. Bottom-up Web services development involves creating a Web service from a Java bean or enterprise bean.
When creating a Web service using a bottom-up approach, first you create a Java class and then use the Web services wizard to create the WSDL file and Web service.

Prerequisites: Install Apache Tomcat6.0.2,Eclipse IDE,Apache Axis-2 1.4.1
Create a new Dynamic Web Project in Eclipse
New-->DynamicWebProject Give the project name as TestServices.
Select the Target runtime Apache Tomcat In the configuration click on modify then select Axis2 webservices as shown below.
Note: To install Axis2 in Eclipse go to windows-->Preferences-->WebServices--> Axis2 Preferences Under the tab Axis2 runtime browse for axis2 runtime location and click ok.


Step: 2  Under src create a java class as shown below

Step:3  Under WebContent-->WEB-INF-->services     
create two folder called  HelloService-->META-INF and paste the service.xml file here as shown below.In the service.xml file you need to specify the Servicename and service class.

Step:4 When you run the project the Deployment descriptor will invoke the services.xml file automatically. Since we are specifying our java class in the services.xml file it will invoke service.xml file and generate the WSDL file on the fly.
Select the project (TestServices)  and right click on it Run As-->Run on server

Step :5 When you click on Services in the browser you can see the list of services and methods defined for the service .In our case we have only one service called HelloService as show below..

Step : 6 When you click on the HelloService you can see the WSDL file. Axis engine will generate wsdl file on the fly for us.

This is how you create a topdown webservices. Now lets go through consuming the webservices.