Application AXIS Start WEB Service Tour

xiaoxiao2021-03-06  31

This article describes the use of AXIS as a development environment to experience the development process of Web services.

One. Introduction This article does not want to introduce the principle of web services, system architecture, etc. We assume that you have learned about some basic concepts, principles such as Web services. This article is mainly for developers who have already learned the concept of Web services, but there is no experience in the Web services. Here we believe that you have a basic knowledge such as Java, XML. If you have other development environments, such as VB, VC is just better.

1. Although we don't want to tell the architecture of the Web service in detail, it is still necessary. Web services are a new type of web application. Unlike other web applications, it is an adaptive, self-description, modular application, and can make, position, and calls across the web. Simple web services can provide services such as weather forecasts or flight information. Once a web service is deployed, other applications can discover and call the deployed service.

2. The AXIS project AXIS frame comes from apache open source organization, which is an open source implementation based on the latest SOAP specifications (SOAP 1.2) and SOAP 1. Attachments specification (from Apache Group) for Java language. There are a lot of popular development tools using AXIS as its feature that implements the web service, such as JBuilder, and the famous Eclipse J2EE plugin Lomboz. The latest version of AXIS is 1.1, which can be downloaded from http://ws.apache.org/axis/index.html. The following figure is the architecture of the AXIS core engine:

figure 1

The entire Axis project includes the following parts:

The message flow system messaging system provides a flexible message delivery framework, which includes handlers, chains, serialization procedures, and reverse sequencer. The handler is an object that handles requests, responses, and failures. The handler can be combined to become a chain, and a flexible deployment descriptor can be used to configure the order of these processing programs. The transmission frame subsystem provides a transmission framework that helps you create your own pluggable transmitter and transmit listeners. Data Coding subsystem AXIS is fully serialized in accordance with the XML Schema specification, and provides functional extensions to use the serializer and deserializer you have customized. Other AXIS fully supports WSDL and logging, errors, and troubleshooting mechanisms. It also provides some tools to use WSDL documents to convert to a client-side call framework and according to classes to generate WSDL definition documents.

The current version of AXIS is: W3C SOAP 1.1 and 1.2; WSDL 1.1; Saaj 1.1 (SUN: SOAP WITHTACHMENTS API for Java); JAX-RPC (Sun: Java API for XML-based RPC) 1.0.

In addition to the AXIS described earlier, Tomcat will also be used herein, which will not be described again. In addition, in order to demonstrate that the Web service is independent of the development environment, and the standard, it is standard, it is standard, which we will use Microsoft's SOAP Toolkit and Microsoft's development environment VB and VC to be a web service client. .

II. Environment Construction Since AXIS itself is based on Java language-based projects, and is published in the web application, it requires an application server as support. In order to facilitate us to choose Tomcat here. Since AXIS itself needs to use packets that process XML information, we recommend using JDK1.4 and install Tomcat 4.1.24. Below is an environmental construction step, and read according to its own situation.

Install JDK1.4.1 Install Tomcat 4.1.24 to C: / Tomcat and verify that the installation is successfully downloaded Axis project package file Axis-1_1.zip After decompression, copy the Axis subdirectory in the WebApps directory in the directory to C: / Tomcat / Under WebApps. Verify AXIS installation: Restart the Tomcat server After opening the browser Enter the URL http: // LocalHost: 8080 / AXIS should appear as shown below, click the link "Validate" to verify that the few Java packs required by AXIS are complete . figure 2

After clicking on the hyperlink Validate, AXIS automatically checks each Java component you need, which is divided into: Required components and optional components, must ensure that all required components exist, as shown in the figure below for authentication.

image 3

three. Web Service server development After two steps, we can start web services! Most people are learning a programming language to start from the Hello World program, and we are no exception. We will provide such a web service, passing it to the name, service return: Hello [Name], welcome to the world of Web services. This is our needs. We will immediately complete our needs according to AXIS, you will find that the original web service can be so simple!

Write the Java class Hello.java, the content is as follows:

Public class hello {

Public String Hello (String Name) {

IF (Name == Null)

Name = ""

Return "Hello" Name ", welcome to the world of Web services!";

}

}

Only there is no need to compile, this file is renamed Hello.jws and copy it to the AXIS application directory C: / tomcat / webapps / axis.

Below we can test the web service, open the browser and enter the URL address corresponding to the file name just created, http: // localhost: 8080 / axis / hello.jWS browser display results:

There is a web service here

Click to see the WSDL

Click on the link on the page to see the WSDL information corresponding to the web service as shown below (we will introduce WSDL in the next section)

-

Targetnamespace = "http:// localhost: 8080 / axis / hello.jws"

XMLns = "http://schemas.xmlsoap.org/wsdl/"

XMLns = "http://www.w3.org/2000/xmlns/"

XMLns: ApacheSoAP = "http://xml.apache.org/xml-soap"

XMLns: sopenc = "http://schemas.xmlsoap.org/soap/encoding/"

XMLns: IMPL = "http: // localhost: 8080 / axis / hello.jws"

XMLns: intf = "http: // localhost: 8080 / axis / hello.jws"

XMLns: wsdlsoap = "http://schemas.xmlsoap.org/wsdl/soap/"

XMLns: xsd = "http://www.w3.org/2001/xmlschema" xmlns: wsdl = "http://schemas.xmlsoap.org/wsdl/">

-

-

-

-

-

-

Namespace = "http:// defaultnamespace" />

-

Namespace = "http: // localhost: 8080 / axis / hello.jws" />

-

-

At this time we have completed the Hello's web service, how do we tell users how to use this service? We only need to tell the user our web service URL address: http:// localhost: 8080 / axis / hello.jws? WSDL is OK! In the next section, we will introduce how to access the corresponding web services through this address.

four. Web Service Client Development In this section we will use three different languages ​​to access the Web services just created, named Java, VB, VC. In order to access Web services using VB and VC, we need to install Microsoft's SOAP Toolkit Development Kit, this kit can be from Microsoft's homepage

Http://download.microsoft.com/download/xml/soap/2.0/w98nt42kme/en-us/soaptoolkit20.exe

Download, download the package and use it by default.

There are two concepts before starting the client development. We must introduce first.

SOAP: Simple Object Access Protocol. This is a simple and lightweight mechanism for exchanging structured and type information using XML pairs in a loose, distributed environment, which is an XML-based protocol. It consists of four parts: SOAP package (Envelop), the package defines what is the content in the description message, who is sent, who should accept it and how to handle their framework; SOAP coding rule (Encoding rules), Used to indicate an instance of a data type that the application needs to use; RPC Repesentation, represents an agreement of remote procedure calls and responses; SOAP binding, uses underlying protocol exchange information.

Although these four parts are part of the SOAP, as a whole, they are defined, but they are functionally intersecting, independent of each other. In particular, envelopes and coding rules are defined in different XML namespaces, which makes it easier to define.

The main design goals of SOAP are concise and scalable. This means that there are some features in the traditional message system or distributed object system will not be included in the core specification of SOAP. These features include: distributed garbage collection; batch messaging / processing; object references; object activation.

WSDL: Web Service Description Language. Using WSDL, we can automate the Web Service agent through this cross-platform and cross-language approach. Just like com and corba IDL files, the WSDL file is agreed by the customer and server. Since WSDL is designed to be able to bind other protocols other than SOAP, we focus on WSDL relationships on HTTP and SOAP. Similarly, since SOAP is currently mainly used to call remote processes and functions, WSDL supports document specifications for SOAP transmission.

The WSDL document can be divided into two parts. The top portion consists of an abstract definition, and the bottom portion consists of a specific description. The abstract part defines SOAP messages independently of platform and language, which does not contain any elements that varies with machines or languages. This defines a series of services, and the very different websites can be implemented.

1. Java client uses Axis tools to make web services as simple as we have previously introduced to create a Web service. Such tools have been included in the AXIS environment in which we have installed in front, it is a Java class, named: org.apache.axis.wsdl.wsdl2java. Open the command line window and go to the web-infrock directory under the AXIS directory. Make sure the Tomcat service is already started, type command: java -djava.ext.dirs = lib org.apache.axis.wsdl.wsdl2java http: // localhost: 8080 / axis / hello.jws? WSDL

The result of this command is to generate a subdirectory localhost / axis / hello_jws in the current directory, with four Java source files, which are:

Hello.java defines a web service interface. There is only one Hello method in this case.

HelloService.java defines how to get a web service interface.

HelloServiceLocator.java interface HelloService concrete implementation.

HellosoapBindingstub.java web service client pile, interacting with the server.

These four Java classes help us handle most of the logic, and we need to add these classes to our project and create a class of our own class to call them. To this end, we will add a class main.java for convenience, so that this class is in the same package with the four classes that have just been produced. The content is as follows:

//Main.java

Package localhost.axis.hello_jws;

Public class main {

Public static void main (string [] args) throws exception {

HelloService Service = New HelloServiceLocator ();

Hello Hello = service.gethello ();

System.out.println ("response:" hello.hello ("can");

}

}

Compile with the following command:

Javac-ClassPath LiB / Axis.jar; lib / jaxrpc.jar localhost / axis / hello_jws / *. java

If you don't have a problem, execute the test program:

Java -djava.ext.dirs = lib -cp. localhost.axis.hello_jws.main // Run results: Response: Hello can, welcome to the world of Web services!

In several classes that are automatically generated by the WSDL2JAVA tool, the class HelloServiceLocator saves this information related to the server, such as the URL address, etc., when the server's address changes but the service is not changed, the string definition in the file is directly modified. No need to regenerate these classes. If you need to modify the content, you can open the file.

2. The VB client has Microsoft SOAP Toolkit, which is also a pleasant thing to call Web services with VB.

Open the VB Development Environment New Standard EXE project, open the Project menu and select Reference Open Component Reference dialog box as shown below: Find and select Microsoft Soap Type Library.

Figure 4

New and editing the form as shown below:

Figure 5

The editing button CALL Click the event handler as follows: (Note that the control name of the form is to correspond to the name in the program)

Private sub calarbtn_click ()

'This approach needs to reference the SOAP TYPE LIBRARY'DIM SOAP AS MSSOAPLIB.SOAPCLIENT in the project.

'Set soap = new mssoaplib.soapclient

DIM SOAP

Set soap = creteObject ("mssoap.soapclient")

ON Error ResMe next

'soap.msoapinit urltext.text

Call soap.msoapinit (urltext.text)

IF Err <> 0 THEN

Msgbox "Initialization SOAP failed:" Err.Description

Urltext.setfocus

Else

If Len (Trim (NameText.Text) = 0 THEN

Msgbox "Please enter your name!"

Nametext.setfocus

Else

ResponseText.text = soap.hello (nametext.text)

END IF

END IF

End Sub

Save the project and run, enter your name and click the button Call.

3. The VC client opens the VC development environment, new project HelloClient, project type is an empty project for Win32 Console Application. The new C Source File file name is: hellosoap.cpp, the editing file content is as follows:

/ / # include "stdafx.h"

#include

#import "msxml3.dll"

USING NAMESPACE MSXML2;

/ / Modify the path specified in the following statement according to the situation of your machine

#import "c: / program files / compon files / mssoap / binaries / mssoap1.dll" /

Exclude ("iStream", "ISEquentialStream", "_large_integer", / /

"_Ularge_integer", "tagstatstg", "_filetime")

USING NAMESPACE MSSOAPLIB;

Void Hello () {

Isoapserializerptr serializer;

IsoapReaderptr Reader;

IsoapConnectorptr Connector;

// Connect to the service

Connector.createInstance (__ uuidof (httpconnector);

Connector-> Property ["endpointurl"] = "http: // localhost: 8080 / axis / hello.jws? WSDL";

CONNECTOR-> Connect ();

// Begin Message

CONNECTOR-> BeginMessage ();

// Create The SOAPSERIALIZER

Serializer.createInstance (__ uuidof (SOAPSERIALIZER);

// Connect The Serializer to the Input Stream of the Connector

Serializer-> Init (_variant_t ((iunknown *) connector-> inputstream);

// build the soap messageageserializer-> Startenvelope (",", ",");

Serializer-> StartBody ("");

Serializer-> StartElement ("Hello", ",", "");

Serializer-> StartElement ("Name", ",", "");

Serializer-> WriteString ("canned");

Serializer-> endelement ();

Serializer-> endelement ();

Serializer-> endbody ();

Serializer-> EndENVelope ();

// send the message to the Web Service

CONNECTOR-> endMessage ();

// let us read the response

Reader.createInstance (__ uuidof (soapreader));

// Connect The Reader to the Output Stream of the Connector

Reader-> Load (_VARIANT_T ((iunknown *) connector-> outputstream), "" "

// Display THE RESULT

Printf ("Response:% S / N", (const char *) reader-> rpcResult-> text);

}

int main ()

{

Coinitialize (NULL);

Hello ();

Couninitialize ();

Return 0;

}

Compile and run the project.

This section is just to demonstrate the Web service created using Axis via VC, as for the specific use of SOAP Toolkit, please refer to the Soap Toolkit Help Manual, please check the relevant documentation.

5. AXIS integration

In order to allow our web application to support web service features, we need to integrate AXIS into our application. Integrated AXIS is simple, first need to copy Axis several JAR package files, these files are copied in the [Axis] / Web-INF / LIB directory, copy these files into our own application directory Web-INF / WEB-INF / LIB. In addition, if you use it is not a Tomcat server, you need to copy Activation.jar, this JAR file can be found in the [Tomcat] / Common / Lib directory!

After copying the JAR file is the configured web.xml, just add configuration information in the web.xml in the Axis to Web.xml in our own application. The most important thing is the following:

Axisservlet

apache-axis servlet

Org.apache.axis.transport.http.axisservlet

Axisservlet

*. jws

WSDL

text / xml

XSD

text / xml

Six summary to this article, I have passed through the above drills, I believe that you have already had a sense of understanding of the web service, but this is just the beginning, we are just very simple to introduce some basic concepts of Web services and demonstrate one. An example of unable to be simple. There are still many other advanced content such as complex types, data security, etc., but there is no relationship. Everything is difficult, I hope this paper can promote everyone understanding and applying the next generation of application model and gives developers who have not been trial. Open a good head.

Reference

IBM Developer Site Web Services Zone http://www-900.ibm.com/developerWorks/cn/xml apache website AXIS project http://ws.apache.org/axis/ Apache Tomcat http: //jakarta.apache. ORG / Tomcat Microsoft MSDN Site http://www.microsoft.com/china/msdn Microsoft SOAP Toolkit 2.0 Download address http://download/xml/soap/2.0/W98NT42kme/EN-US /Soaptoolkit20.exe axis package download address: http://ws.apache.org/axis/dist/1_1/ w3c Web service http://www.w3.org/2002/ws/

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

New Post(0)