Develop Web Services with AXIS

zhaozj2021-02-16  168

?

AXIS Introduction AXIS is the SOAP engine launched by Apache organizations, and the AXIS project is the successive project of Apache's famous SOAP project. The latest version is the 1.1 version developed by Java. Axis v1.1 package can be downloaded from http://ws.apache.org/axis/dist/1_1/. ??? The following describes the development of the Web Service with a specific example.

purpose

?

?? Understand the working principle of WebService, implement a web service. This Service provides the following services: increasing deposits, reducing deposits and returning deposit balances.

platform

? ??? J2SDK1.4 Tomcat5.0 Axis

step

1. ???????? Install J2SDK

?????? d: /j2sdk1.4

2. ???????? Install Jakarta-Tomcat-5.0

?????? d: / tomcat

3. ???????? Installing the AXIS ?????? Just use the downloaded AXIS software to decompress, copy the "Axis" directory under the "WebApps" directory to the Tomcat installation directory "WebApps" directory

?????? d: / tomcat / webapps / axis

AXIS configuration

????? The system variable that needs to be configured is shown in the table below:

?????? Catalina_home ?????? d: / tomcat ?????? axis_home ??????% CATALINA_HOME% / WebApps / Axis ?????? AXIS_LIB ?????? % AXIS_HOME% / LIB ?????? ?????? AxisclassPath ??????% AXIS_LIB% / AXIS.jar;% AXIS_LIB% / Commons-Discovery.jar; ??????% AXIS_LIB % / commons-logging.jar;% AXIS_LIB% / jaxrpc.jar; ????% AXIS_LIB% / saaj.jar;% AXIS_LIB% / LOG4J-

1.2.8

.jar; ??????% axis_lib% / xml-apis.jar;% AXIS_LIB% / XERCESIMPL.JAR

You can also directly add all the .jar files in the "lib" directory in the AXIS package to the system environment variable ClassPath. D: /tomcat/webapps/axis/web-inf/lib/axis.jar; d: /tomcat/webapps/axis/web-inf/lib/axis-ant.jar; D: / Tomcat / WebApps / Axis / Web -Inf / lib / commons-discovery.jar; d: /tomcat/webapps/axis/web-inf/lib/commons-logging.jar; d: /tomcat/webapps/Axis/web-inf/lib/jaxrpc.jar D: / Tomcat / WebApps / AXIS / Web-INF / LIB / LOG4J-

1.2.8

.jar; d: /tomcat/webapps/axis/web-inf/lib/saaj.jar; d: /tomcat/webapps/AXis/web-inf/lib/wsdl4j.jar 4. ???? Access HTTP: / / Hostname: 8080 / axis / and test the link on the web page to work properly 5. ????????? Service release? Axis provides two service release methods, one is instant deployment, one Customization release (Custom deployment). For instant release support is one of the features of AXIS, using instant release enables users to provide the source code for the Java class providing service, you can quickly release it into a web service. Whenever the user calls this type of service, AXIS will automatically compile, even if the server is restarted, it is not necessary to do anything, it is very simple and fast. Using instant release first requires a Java source file that implements service functions, change its extension to .jws (Java Web Service Abbreviation), then place the file into the "... / WebApps / Axis" directory. The instant release is an exciting technology, which makes the development of web services are so simple; however, is not always the best choice, ratio? If some application systems are available, we There is no purchase source code, only .class files, but we hope to release some of the functions of this application system into a web service, enabling it to generate in a larger range, this time I am discouraged. In addition, instant publishing techniques are not flexible, and more service configurations cannot be made, which makes it unable to meet the needs of some particular systems. Therefore, AXIS provides another service release method, which is customized, and below is described in detail below.

? Create your own WebService service class //bank.java

Package WebService.bank;

/ **

* @Author ray

* /

?

Public class bank {

?????? public static double balance = 100;

??????

?????? public synchronized double balance () {

?????????????? Return balance;

??????}

??????

?????? public synchronized double deposit (double amount) {

????????????? // realize the deposit

????????????? Balance = Balance AMOUNT

????????????? Return balance;

??????} // deposit ()

??????

?????? public synchronized double withdraw (double amount) {

????????????? // realize withdrawal

????????????? f (balance> = amount)

???????????????????? alance = balance

????????????? ELSE

???????????????????? system.out.println ("caught");

????????????? Return balance;

??????} // welbit ()

??????

??????

}

Compile it into a .class file, place it into the "... / WebApps / Axis / Web-INF / CLASS / WebS / web" directory 6. ???????? Creating a WSDD file settings to provide service information

This file is responsible for describing the name, entrance and other information of the service, and its contents are as follows: deploy.wsdd

7. ???????? Deployment (released) Your webservice

"... / WebApps / Axis / Web-INF / CLASS / WebService / Bank" directory

Java -cp% AxisclassPath% org.apache.axis.client.adminClient Deploy.wsdd

8. ???????? Access http://127.0.0.1:8080/axis/services/bank?wsdl link, see if your WebService is successful

?

9. ???????? Writing client code (can use AXIS with API)

?????? code slightly see Newtest.java

?????? Where, org.apache.axis.client.call and org.apache.axis.client.Service are two comparison class, and the general client program wants to access a web service. A client's service object and a CALL object, first set the corresponding parameters to the Call object, including the location of the service, the location, the entrance parameters, the return value type, and the like, and finally call the invoke method access service of the Call object.

????????????? .........

????????????? service service = new service ();

????????????? Call calld = (call) service.createcall ();

????????????? Double D1, D2;

????????????? // set the access point

????????????? Calld.SetTargetendPointDready ("http: // localhost: 8080 / axis / service / bank");

????????????? // set the operand ????????

????????????? CallResult.SetoperationName ("balance");

????????????? CallResult.setRetURNTYPE (XMLTYPE.XSD_DOUBLE);

????????????? system.out.println ("Welcome to Bank");

????????????? system.out.println ("Your balance:" CallResult.invoke (new object [] {}) "yuan");

????????????? .........

?

10. ???????? Run the client program to view the output result

Run client program newjava

Command format: Deposit (d) / withdraw (w)? Double or quit (q)

Java Newjava

Save money input format? If you deposit 100 yuan: D 100

Take money input format? If you take it out of 20 yuan: W 20

When the balance is insufficient:

转载请注明原文地址:https://www.9cbs.com/read-8382.html

New Post(0)