Develop Web Services step by step with Apache AXIS
----Call Sharatu instructions and conventions:
This article mainly describes how to implement Web Services using the API provided by the Apache open source project axis. The examples mentioned in this article are only for the convenience of the description of this article, please forgive me for the improper.
The reader of this article should be based on Java Web application development. Should have seen the basic norms such as wsdl,soap,xml. Familiar with Eclipse+myeclipse development environment.
This article can be reproduced at will use, but to retain the author's signature. I. Environmental preparedness
Using axis to develop Web services requires the preparation of the Web server, the axis API. The Web container used in this article is Tomcat5.5, and the Axis API uses version 2.
1.1 software Download Preparation
Tomcat Download Address: http://tomcat.apache.org/download-55.cgi#5.5.20
Axis Standard Pack:
Http://ftp.wayne.edu/apache/ws/axis2/1_0/axis2-std-1.0-bin.zip
Axis War Package:
Http://ftp.wayne.edu/apache/ws/axis2/1_0/axis2.war
Axis Eclipse Plug-in (code generation tools and packaging tools):
Http://apache.justdn.org/ws/axis2/tools/1_0/Axis2_Code_Generator.zip
Http://apache.justdn.org/ws/axis2/tools/1_0/Axis2_Service_Archiver.zip
Eclipse+myeclipse: Can be downloaded to the official website (this article is 3.2+5.0ga)
1.2 Installation
A. First build the development environment, you need to extract the downloaded eclipse to a directory.
B. Extract two plug-in from the downloaded axis to the plug-in subdirectory under the Eclipse installation directory.
C. Installation of Myeclipse5.0ga. Then start MyEclipse and choose "File->new->other" to find the following wizards, which will be a very important tool for this article.
D. Start the deployment environment for Web services below. Will download the
The Tomcat is decompressed to a directory. Completing the Web container
The installation.
E. Copy the Axis2.war package to the WebApps under the Tomcat installation directory
Table of Contents.
F. Start Tomcat (the Startup.bat;linux,unix environment for Tomca_home/bin in Windows is startup.sh file), open browser input and access: Http://ip:port/axis2 to view. (If there is no modification of the file with the child this address should be Http://localhost:8080/axis), if you can see the following page, the installation is complete.
Second, Quick Start
When the environment is ready, start with a simple example. For an understanding of the approximate process for developing Web services using axis. This example is SayHello, where the requester enters a name string and returns a greeting.
For example: Enter Tom, then return the thing Hi,tom.how are you.
2.1 Write WSDL
A Start MyEclipse, create a new WebApps (File->new->project->web project), give Project Name SayHello, and others remain unchanged.
B Select the File->new-other menu, find Myeclipse->web Services after entering, and select WSDL.
C. Select the "src" directory as the value of "Enter or select the parent folder" and the "File name" value is given as sayhello.wsdl. Click "Next" to go to the next step.
D. Set the target namespace to "http://ws.tonyzhangcn.org/SayHello/". When generating code, this namespace is typically the name of the package, for example: Org.tonyzhangcn.ws.sayhello. These values can be set as needed.
E. Click the Finish button to see the interface of the WSDL designer provided by MyEclipse. You can see that the designer has added a current operation by default for WSDL.
This is the "newoperation" in the diagram. Now rename it to SayHello, as shown below:
Then click the "Source" tab in the design interface to see its code. As follows: You can see that we have defined a SayHello web Services, and she provides a SayHello method that she can accept a string (actually Tns:sayhellorequest object, She encapsulates the string, sayhellorequest the input parameter of the type and returns the Sayhelloresponse result of a string (in fact, the Tns:sayhelloresponse object, which she encapsulates the string) type. For more information about WSDL, refer to the specification documentation for the consortium.
<?xml version= "1.0" encoding= "UTF-8"?>
<wsdl:definitions xmlns:soap= "http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns= "http://ws.tonyzhangcn.org/ sayhello/"xmlns:wsdl=" http://schemas.xmlsoap.org/wsdl/"xmlns:xsd=" Http://www.w3.org/2001/XMLSchema "Name=" SayHello "targetnamespace=" http://ws.tonyzhangcn.org/SayHello/">
<wsdl:types>
<xsd:schema targetnamespace= "http://ws.tonyzhangcn.org/SayHello/" >
<xsd:element name= "Sayhelloresponse" type= "xsd:string"/>
<xsd:element name= "Sayhellorequest" type= "xsd:string"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name= "Sayhelloresponse" >
<wsdl:part