Creating and deploying a simple WebService is not as hard as you think. For this example we are going to work with Apache Axis WebService. Axis is essentially a SOAP engine ,a framework for constructing SOAP processors such as clients, servers, gateways, etc.
Apache Axis is a SOAP toolkit that makes it easy to create, deploy, and consume web services. By using Axis, you will be able to quickly convert existing Java functionality into web services, deploy those services, and be able to communicate with them remotely via the Internet, usually through firewalls (if necessary).
More precisely, Axis is an implementation of SOAP. Most people like to think of it as a toolkit. From the programmer's point of view, it's like an API. It makes it easy for you to communicate - with SOAP - to a remote object, without having to worry about the details associated with the protocol. In practice, it is a lot like using RPC, CORBA, RMI, or any of the other distributed computing technologies you may have experience with. The process is largely the same: you describe the target of your communication, invoke the remote method and marshall your parameters, and then demarshall the return values. Since AXIS makes this process simpler than ever, development is a breeze.
Well, let's start coding...
For this example we are going to use:
- Java (here I'm using JDK 1.7, Click here if you need help installing Java JDK in Windows)
- Apache Tomcat v7.xx
- Eclipse Luna
Install Apache Tomcat and add it to Eclipse... File --> New --> Other. Type in server, and follow the wizard.
Open Eclipse and create a "Dynamic Web Project"
For project Name: JavaApacheAxisWebService
On your Eclipse project, expand Java Resources and under /src create a
new class: MyJavaWebServiceHelloWorld
and for Package: rolandofebrero.com.web.service
Now, double click on MyJavaWebServiceHelloWorld.java and add the following code:
Right click on MyJavaWebServiceHelloWorld.java --> Web Services --> Create Web Service
On the next screen, make sure you have selected Tomcat and Apache Axis in both service and client. Please see the image bellow:
If after clicking finish you see any error regarding to you server, make sure you can start Tomcat with no errors. If not, delete your server, and add it again. Server should start with no errors before creating WebService.
If everything was OK, your project should look like this:
If the server started correctly, JavaApacheAxisWebService and JavaApacheAxisWebServiceClient are automatically deployed to Tomcat server.
By default Eclipse provides a Web service Test Client Window in which we can consume our service
If we click on getEndpoint() link, it will provide us with the endpoint of our service, which is:
http://localhost:14823/JavaApacheAxisWebService/services/MyJavaWebServiceHelloWorld
put that endpoint in your browser and add ?WSDL at the end. We will see the WSDL created. If you want to consume this service, you might need the WSDL, or just use SoapUI and create a soap project and start testing this new service....
You can download the code for this project from my GitHub account:
https://github.com/rolando-febrero/JavaApacheAxisWebService
https://github.com/rolando-febrero/JavaApacheAxisWebService
Programming thought of the day:
- My software never has bugs. It just develops random features.
No comments:
Post a Comment