How to Use axis to build a soap Application

Source: Internet
Author: User
Tags echo message

All source code: http://download.csdn.net/detail/feichenwangyalin/7911159

You can import the soapserver and soapclient to eclipse and add axis to Tomcat's webapps.


1. Basic Concepts
1.1 concepts of soap

Soap is a Simple Object Access Protocol. It is a protocol specification for data exchange. It is a lightweight, simple, XML-based protocol (a subset of standard General Markup Language. Simply put, soap is also an implementation form of web services and a service released by a system, but its data exchange form is XML.

Three important parts of soap are: Interface Program (server code), WSDL (Web servicedescription language), and WSDD (Web servicedeploy description ), readers who are not very clear about the basic concepts can start with Baidu.


1.2 Why use soap

There are multiple forms of WebService implementation, and soap is only one form of interface implementation. First of all, we have to understand why our system needs to release interfaces externally. Let's talk about telecommunications software. We know that a telecom operator needs various systems to support its various businesses, although they are all operational vendors, the various systems in them are not necessarily developed by a software manufacturer. For example, the boss (Operation Support System) is developed by Company A, while the CRBT business system is developed by Company B, A marketing system is developed by Company C. Although these systems belong to the same company, it is obvious that the source code of Company A's boss system cannot be open to other systems, therefore, the interaction between these systems needs to be achieved through mutual interface calls, and the interfaces released by each system of this interface include HTTP interface and soap interface.

 

2. Use axis to develop a soap Application
2.1 axis Introduction

Axis is an encapsulation of Java WebService officially provided by Java. Its biggest advantage is that it can directly generate client code based on the WSDL provided by the server, and can call the server interface transparently as a caller, just as the server interface is local.

 

2.2 server interface development

Next we will conduct an experiment to develop a simple interface and describe how to build a project through ant script to generate the server interface code, WSDL, WSDD, and jar package for the client, these are the four elements of the soap application we mentioned in 1.1.

Shows the build process:


The most important build. xml source code is given below. This build process is fully constructed in the order of construction, with annotations that readers can refer to and understand:


<? XML version = "1.0"?> <Project name = "soapserver" basedir = "."> <! -- Define various paths --> <property name = "srcdir" location = "src"/> <property name = "outputdir" location = "output"/> <property name = "classdir "Location =" output/classes "/> <property name =" jardir "location =" output/lib "/> <property name =" srcjarfile "location =" $ {jardir} /soapserver. jar "/> <property name =" java2wsdldir "location =" output/WSDL "/> <property name =" genwsdddir "location =" output/WSDD "/> <property name = "wsdl2jav Adir "location =" output/Java "/> <property name =" wsdl2classdir "location =" output/class "/> <property name =" wsdl2jarfile "location =" $ {jardir }/soapserver_axis.jar "/> <! -- Define the axis support package --> <property name = "axishome" location = "lib"/> <property name = "name" value = "testsoap"/> <property name =" version "value =" 1.0 "/> <property name =" author "value =" author: martin "/> <! -- Specify axis classpath --> <path id = "axis. classpath "> <fileset dir =" $ {axishome} "> <include name = "**/*. jar "/> </fileset> </path> <taskdef resource =" axis-tasks.properties "classpathref =" axis. classpath "/> <! -- Some basic information --> <echo message = "----------- $ {name }$ {version} [$ {author}] ------------"/> <! -- File directory initialization --> <target name = "init"> <Delete dir = "$ {outputdir}"/> <Delete dir = "$ {classdir}"/> <Delete dir = "$ {jardir}"/> <Delete dir = "$ {java2wsdldir}"/> <Delete dir = "$ {wsdl2javadir}"/> <Delete dir = "$ {wsdl2classdir} "/> <Delete dir =" $ {genwsdddir} "/> <mkdir dir =" $ {outputdir} "/> <mkdir dir =" $ {classdir }" /> <mkdir dir = "$ {jardir}"/> <mkdir dir = "$ {java2wsdldir}"/> <mkdir dir = "$ {genwsdddir}"/> <mkdir dir = "$ {WS Dl2javadir} "/> <mkdir dir =" $ {wsdl2classdir} "/> </Target> <! -- Start compilation, generate the classes file --> <target name = "compile" depends = "init"> <javac srcdir = "$ {srcdir}" destdir = "$ {classdir}"/> </ target> <! -- Generate a jar package based on the generated classes --> <target name = "makejar" depends = "init, compile "> <jar destfile =" $ {srcjarfile} "basedir =" $ {classdir} "/> </Target> <! -- Generate WSDL --> <target name = "buildjava2wsdl"> <axis-java2wsdl classname = "com. martin. intrefaces. soapisayhello "location =" http: // localhost: 8080/axis/services/soapisayhello "namespace =" http://intrefaces.martin.com "output =" $ {java2wsdldir}/soapisayhello. WSDL "style =" RPC "> <classpath> <pathelement Path =" $ {classdir} "/> </classpath> </axis-java2wsdl> </Target> <! -- Generate the corresponding Java code and WSDD file according to the generated WSDL --> <target name = "buildwsdl2java"> <axis-wsdl2java all = "true" url = "$ {java2wsdldir} \ soapisayhello. WSDL "deployscope =" request "output =" $ {wsdl2javadir} "serverside =" true "testcase =" false "noimports =" false "typemappingversion =" 1.2 "> </axis-wsdl2java> <! -- Deploy the generated deploy. WSDD moves to the specified location and rename --> <move tofile = "$ {genwsdddir}/soapisayhello. WSDD "file =" $ {wsdl2javadir}/COM/Martin/intrefaces/deploy. WSDD "> </move> </Target> <! -- Compile and package the Java code generated by the WSDL --> <target name = "compilewsdl2jar"> <! -- Compile it into a class file --> <javac srcdir = "$ {wsdl2javadir}" destdir = "$ {wsdl2classdir}"> <! -- Reference the jar package of axis during compilation --> <classpath> <fileset dir = "$ {axishome}"> <include name = "**/*. jar "/> </fileset> </classpath> </javac> <! -- Package the class file into jar --> <jar destfile = "$ {wsdl2jarfile}" basedir = "$ {wsdl2classdir}"/> </Target> </Project>


After the build, we can view the product, as shown in:



Classes Folder: the class file compiled by the server interface;

Java Folder: Java code is used for the client generated according to the WSDL;

Class Folder: the class file compiled by the client code;

Lib Folder: soapserver_axis.jar is the interface package for the client to call interfaces. This package is used to place it in the reference package of the client project;

Soapserver. jar is the interface implementation package used by the server. The package is changed to be placed under the Lib package of axis;

WSDL and WSDD packages: generated WSDL and WSDD files


3. Test the soap Interface

Note: The Source Code provided in this Article has already completed the following steps. You can perform the test by yourself according to the following steps:


3.1 deployment Interface

There are two steps to deploy the server: 1. Place the corresponding server implementation package under the Lib corresponding to axis;

2. Add the content of the service node in the generated WSDD file to the WSDD file of Axis. Note that you must manually:

<Parameter name = "classname" value = "com. Martin. intrefaces. soapisayhellosoapbindingimpl"/>:

<Parameter name = "classname" value = "com. Martin. intrefaces. soapisayhello"/>

Because the former is the default class name when axis is generated. If this is not the case, you need to manually change it.


3.2 test interface

1. First, visit the following address to check whether the service has been published successfully:

Http: // ip: Port/axis/servlet/axisservlet. If the soapisayhello service exists in the service list, the service has been released successfully.

2. We put the constructed soapserver_axis.jar into the soapclient project and add references.

3. Run cienttester. Java to test whether the request is successful. If the output is "Call soap interface: Hello, Ding xiangyong, and return code: 000000", the interface is successfully called.



How to Use axis to build a soap Application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.