Using axis, it is very simple to publish a web service. Although the process and relatedCodeLong. I used these software in this post: Axis 1.1, eclipse 2.1, and eclipse Tomcat plug-in 2.2 (sysdeo Tomcat plugin ). The release method is as follows:
The service I want to publish is a library store. The publishing methods include adding books addbook, listbooks, and deletebook. For the sake of simplicity, only one method for adding books is released, because the release of other methods is similar.
1. Create a tomcat project named bookstore in eclipse. Note that this option is available only when the Tomcat plug-in mentioned above is installed. If there is no installation, you can create a Java project, then manually create the necessary directory structure (WEB-INF, etc.), and manually add the <context> item corresponding to the project in Tomcat server. xml.
2. Create a library class (COM. Bookstore. model. Book). The book has three attributes: name, ISDN number, and page number. 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) {ISDN = String ;} Public Void Setname (string) {name = String ;} Public Void Setpage ( Int I) {page = I ;}}
3. Create a class (COM. bookstore. booksvc), this class is the actual function class, which has only one public addbook () method, and only one of its parameters is the book to be added. The Code is as follows:
PackageCom. Bookstore;ImportCom. Bookstore. model. Book;Public ClassBooksvc {Public VoidAddbook (Book ){//Here you save a book into databaseSystem. Out. println ("book has been added .");}}
4. Now, extract the downloaded axis to a folder, which is assumed to be removed to c: \ axis-1_1. Copy all. Jar files under the c: \ axis-1_1 \ webapps \ axis \ WEB-INF \ lib directory to your web applicationProgramUnder the WEB-INF \ Lib, then copy the Web. xml under the c: \ axis-1_1 \ webapps \ axis \ WEB-INF directory to the WEB-INF of your web application. This step is equivalent to configuring axis in your web application.
5. To let axis know which services you want to publish, you have to create a file named WEB-INF under the server-config.wsdd with the following content:
<? 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. sendminimizedelements" Value = "True" /> < Requestflow > < Handler Type = "Java: org. Apache. axis. Handlers. mongoshandler" > < Parameter Name = "Scope" Value = "Session" /> </ Handler > < Handler Type = "Java: org. Apache. axis. Handlers. mongoshandler" > < 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. urlmapper" /> < 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" /> < Handler Type = "Java: org. Apache. axis. Handlers. http. httpauthhandler" /> </ Requestflow > </ Transport > </ Deployment >
This file contains three services: version, adminservice, and booksvc. There is another way to generate this file, as if axis recommends using this generation method, it is to write a deploy in the same directory. WSDD file (skip to the next step if you do not want to view it). 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, deploy. WSDD contains only the description of our service, confirm that tomcat has been started, and then generate the server-config.wsdd file with the following command in the same directory:
Java org. Apache. axis. Client. adminclient-lhttp://Localhost: 8080/bookstore/services/adminservice deploy. WSDD
Bookstore is the virtual path of my web application.
6. Restart Tomcat and access the path http: // localhost: 8080/bookstore/services. You can see that three Web services are released, for example. Click the WSDL link after each service to view the corresponding WSDL description.
Related links:
- Use axis to publish simple web services (Supplement)