Use AXIS to release simple web services

xiaoxiao2021-03-06  47

Using AXIS, it is very simple to publish a web service, which is not simple to be simple, although it seems a bit long. I used these software in this post: AXIS 1.1, Eclipse 2.1 and Eclipse Tomcat Plugin. The release method is as follows:

The service I want to post is a book store. The method published has a book addbook, list books listbooks, delete books deletebook, and more, for simplicity, only one to add a book method, because other methods are released.

1. First, a new Tomcat project called BookSe is newly created in Eclipse, pay attention to the previous Tomcat plugin to have this option. If you do not have a Java project, you can create the necessary directory structure (Web-INF et al.) And manually add the item corresponding to the project in the server.xml of Tomcat.

2, next to create a book (com.bookstore.model.book), the book has the name, ISDN number, and the number of pages, this is a bean class, the code is as follows:

Package com.bookstore.model; public class book {private string name; private string isdn; private

int

Page; public string getisdn () {

Return

ISDN;} public string getname () {

Return

Name;} PUBLIC

int

GetPage () {

Return

Page;} PUBLIC

Void

Setisdn (String String) {isdn

=

String;} PUBLIC

Void

SetName (String String) {Name

=

String;} PUBLIC

Void

SetPage

int

I) {page

=

I;

3, next to establish a class (com.bookstore.booksvc), this class is the actual function class, which has only one public addbook () method, and its parameter is only one of the books to add. . code show as below:

Package com.bookstore; import com.bookstore.model.book; public class booksvc {public Class Booksvc {public

Void

Addbook (book book) {

//

Here You Save a book Into Database

System.out.println (

"

Book has begsed.

"

}}

4, now, unzip the downloaded AXIS to a folder, here you can solve it C: / AXIS-1_1. Copy all the .jar files in the C: / Axis-1_1 / Webapps / Axis / Web-INF / LIB directory to your web application Web-INF / LIB, then put C: / AXIS-1_1 / WebApps Web.xml under the / axis / web-infroduct to copy to your web application Web-INF. This step is equivalent to configured AXIS in your web application.

5, in order to let AXIS know which services you want to release, you have to build a file called Server-Config.WSDD under Web-INF, as follows:

XML Version = "1.0" encoding = "UTF-8"

?>

<

DEPLOYMENT

XMLNS

= "http://xml.apache.org/axis/wsdd/"

XMLns: Java

= "http://xml.apache.org/axis/wsdd/providers/java"

>

<

GlobalConfiguration

>

<

Parameter

Name

= "adminpassword"

Value

= "admin"

/>

<

Parameter

Name

= "attachments.directory"

Value

= "C: / Eclipse / Workspace / Bookstore / Web-INF / ATTACHMENTS"

/>

<

Parameter

Name

= "attachments.implementation"

Value

= "Org.apache.axis.attachments.attachmentsImpl"

/>

<

Parameter

Name

= "SendxSITYPES"

Value

= "True"

/>

<

Parameter

Name

= "SendMultirefs"

Value

= "True"

/>

<

Parameter

Name

= "Sendxmldeclaration"

Value

= "True"

/>

<

Parameter

Name

= "Axis.sendminimized" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Value

= "True"

/>

<

Requestflow

>

<

Handler

Type

= "java: org.apache.axis.handlers.jwshandler"

>

<

Parameter

Name

= "scope"

Value

= "session"

/>

Handler

>

<

Handler

Type

= "java: org.apache.axis.handlers.jwshandler"

>

<

Parameter

Name

= "scope"

Value

= "Request"

/>

<

Parameter

Name

= "EXTENSION"

Value

= ". jwr"

/>

Handler

>

Requestflow

>

GlobalConfiguration

>

<

Handler

Name

= "LocalResponder"

Type

= "java: org.apache.axis.transport.local.localResponder" />

<

Handler

Name

= "Authenticate"

Type

= "java: org.apache.axis.handlers.simpleAuthenticationHandler"

/>

<

Handler

Name

= "Urlmapper"

Type

= "java: org.apache.axis.handlers.http.urmapper"

/>

<

Service

Name

= "Version"

Provider

= "Java: RPC"

>

<

Parameter

Name

= "AllowedMethods"

Value

= "getversion"

/>

<

Parameter

Name

= "ClassName"

Value

= "org.apache.axis.version"

/>

Service

>

<

Service

Name

= "BOOKSVC"

Provider

= "Java: RPC"

>

<

Parameter

Name

= "AllowedMethods"

Value

= "*"

/>

<

Parameter

Name

= "ClassName"

Value

= "com.bookstore.booksvc"

/>

Service

>

<

Service

Name

= "Adminservice"

Provider

= "Java: MSG"

>

<

Parameter

Name

= "AllowedMethods"

Value

= "Adminservice"

/>

<

Parameter

Name

= "enableremoteadmin"

Value

= "false"

/>

<

Parameter

Name

= "ClassName"

Value

= "org.apache.axis.utils.admin"

/>

<

Namespace

>

http://xml.apache.org/axis/wsdd/

Namespace

>

Service

>

<

TRANSPORT

Name

= "Local"

>

<

Responseflow

>

<

Handler

Type

= "LocalResponder"

/>

Responseflow

>

TRANSPORT

>

<

TRANSPORT

Name

= "http"

>

<

Requestflow

>

<

Handler

Type

= "Urlmapper"

/>

<

Handlertype

= "java: org.apache.axis.handlers.http.httpauthhandler"

/>

Requestflow

>

TRANSPORT

>

Deployment

>

Three services are released in this file: Version, Adminaservice and our Booksvc. There is also a way to generate this file, as if AXIS is recommended to use this generated method, write a deploy.wsdd file in the same directory (if you don't want to see it directly to the next step), the content is as follows:

<

Deployment

XMLNS

= "http://xml.apache.org/axis/wsdd/"

XMLns: Java

= "http://xml.apache.org/axis/wsdd/providers/java"

>

<

Service

Name

= "BOOKSVC"

Provider

= "Java: RPC"

>

<

Parameter

Name

= "ClassName"

Value

= "com.bookstore.booksvc"

/>

<

Parameter

Name

= "AllowedMethods"

Value

= "*"

/>

Service

>

Deployment

>

That is to say that the deploy.wsdd contains only the description of our services, confirming that Tomcat has started, then generate server-config.wsdd files in the same directory:

Java org.apache.axis.client.adminClient

-

LHTTP:

//

Localhost: 8080 / bookstore / Services / Adminaservice Deploy.wsdd

Where BookStore is the virtual path of my web application.

6, restart Tomcat, access path http: // localhost: 8080 / bookstore / services, you can see that three web services are released now, as shown below. Clicking on the WSDL link after each service can see the corresponding WSDL description.

Related Links:

Use AXIS to release a simple web service (supplement)

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

New Post(0)