To follow this tutorial, you need the following software and resources.
Software or Resource | Version Required |
Download bundle | |
version 6 or version 5 | |
Apache Axis 2 | |
Java EE-compliant web or application server | Tomcat web server 6.0 |
Downloading the Apache Axis2 WAR file
Apache Axis2 can be downloaded here. Download the WAR (Web Archive) distribution, so you do not have to build the WAR file yourself. The download is in the form of an archive file. Later you unpack the archive to your server.
Creating an Axis2 Web Service
With MyEclipse IDE (eclipse), you can create an Axis2 web service from a Java class. You can only do this from a Dynamic Web project. In this tutorial, create an Axis2 web service in that project (creating the Java class at the same time) and deploy the Axis2 web service to a server.
Testing an Axis2 Web Service
Goto ServiceWSSoapBindingImpl.java Class and put SOP(System.out.println("Testing Web Service");) inside your method.
Navigate to wsdl file "ServiceWS.wsdl" Right-click select Web Serives-->> Test With Web Service Explorer. Expand to method level and type input value. Click on Go, MyEclipse IDE (eclipse) will display output on console.
- Click the New Project icon or File -> New Project. The New Project wizard opens, select show All Wizards. From the Web category, select a Dynamic Web project. Click Next.
- Name the project AxisWS. Check that you are using the project folder name and location that you want. It is up to you whether to share the project.
- Select the Target Runtime as Tomcat, if not available in dropdown then click New button and select Tomcat 6x from New Server Runtime wizard. Provide the Tomcat installation directory path and also apecify the installed JRE. Click Finish, and the MyEclipse IDE (eclipse) creates the Target Runtime for Tomcat.
- Click on Next and continue with the Default options. Click Next to fill Context Root, Content Directory and Java Source Directory. Click Finish, and the MyEclipse IDE (eclipse) creates the Dynamic Web Project.
- Right-click the src node. The context menu opens. In the context menu, choose New -> Class. The New Java Class opens. Provide the package name and java class name. Click Finish, and the MyEclipse IDE (eclipse) creates the Java Class under the provided package name.
- Create a method with the qualified name and provide the parameters as per the requirement. Here I'm creating a method call getRequestParamFromWS() with the method signature String and the arguments as a String parameter "value".
- Double check the Axis, as mentioned earler it should be deployed on Tomcat which we have configured while creating the Dynamic Web Project.
- Right-click on the Java Class, goto Web Services option and select Create Web Service. The Create Web Service will open a New wizard with more options. Web Service type should be "Bottom up Java bean Web Service" Service Implementation "com.sravan.ServiceWS Client type "Java Proxy" click on Next. The next screen display's the wsdl file name and the methods available under the Java Class.
- Select the appropriate method and Click Next. If your Tomcat server is not running, the MyEclipse IDE (eclipse) will prompt for Start server. Click for Start server, MyEclipse IDE (eclipse) will start your Tomcat server. Click Finish to complete the WSDL file creation process.
- Navigate to wsdl file location. Project-->> WebContent-->>wsdl-->>ServiceWS.wsdl. Right-click on wsdl file and goto Web Service option, select Generate Java Bean Skeleton option.
- Web Service wizard will open, Web Service type should be "Top down Java Bean Web Service", Service definitation /AxisWS/WebContent/wsdl/ServiceWS.wsdl Client type "Java Proxy". Click Next to choose skeleton folder. Click Next will lead to the auto generated code. Click Finish to complete the process.
- Similarly you can generate the Web Service Client code as well, by choosing the Generate Client option displayed under Web Service Java Bean Skeleton option.
- Web Service is completed, you can Add Web Capabilities for this project. While adding the Web capabilities to your peoject choose Web Content folder, or you can name it as a Web Root while creating the Dynamic Project.
- Create an ANT file build.xml to deploy your web application on Tomcat, after deployment type http://yourip:port/AxisWS/services/AxisWS your browser will show a message like "Hi there, this is an AXIS service!".
6 comments:
I'm new bee to Java web services, this tutorial is very useful. Thanks for your efforts to create this tutorial.
my pleasure...
Hello Sravan, is there any way how we can create a Webservice from a WSDL?
Hi Krishna,
Creating web service and creating web service client are two different tasks. Creating a web service means your creating wsdl file where you mention the details of the method you want to expose as a service and url etc. If you want to create a web service client you can do it using wsdl file.
Thanks,
Sravan Modugula.
Hi Sravan,
Thanks for this post. I try to test the generated client from a servlet. I got failures. The testing servlet to invoke the generated client stub is as follows:
public class ServiceServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ServiceServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
ServiceWSSoapBindingStub stub = new ServiceWSSoapBindingStub();
stub.getRequestParamFromWS("My testing");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
faultDetail:
{http://xml.apache.org/axis/}exceptionName:org.apache.axis.NoEndPointException
{http://xml.apache.org/axis/}stackTrace:No endpoint
at com.service.ServiceWSSoapBindingStub.getRequestParamFromWS(ServiceWSSoapBindingStub.java:92)
Hi,
Sorry for the delayed response, I was on a vacation. I hope you might have resolved the issue, if not following are my findings.
You’re directly calling the generated stub instead of using the locator to obtain port
ServiceWSSoapLocator service = new ServiceWSSoapLocator();
ServiceWSSoapPortType port = service.getserviceWSSoapPort();
port. getRequestParamFromWS("My testing");
I guess this will resolve your issue, let me know if you still face any issue after making these changes.
Post a Comment