Axis2 released WebService

Source: Internet
Author: User
Tags wsdl

First, Introduction

Apache Axis2 is the next generation of Apache Axis. Although supported by the Axis 1.x handler model, AXIS2 is more flexible and extensible to the new architecture. Axis2 is written on a new architecture and is not using the usual code of Axis 1.x. The power to support the development of AXIS2 is to explore a more modular, flexible, and efficient architecture that can easily be plugged into implementations of other relevant WEB service standards and protocols such as Ws-security, ws-reliablemessaging, and so on. Apache Axis2 is a subsequent version of Axis and is a new generation of soap engines. Official website: http://axis.apache.org/axis2/java/core/index.html


Second, download

Apache Axis2 download page: http://axis.apache.org/axis2/java/core/download.cgi (current latest version 1.6.2)

Apache Axis2 Binary Distribution (1.6.2): Http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip

WAR Distribution:http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-war.zip

Eclipse plugin:

Service Archive Wizard-eclipse plug-in (used to package the services code into a plug-in with a suffix. aar file):



Http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/Java/core/1.6.2/axis2-eclipse-service-plugin-1.6.2.zip

Code Generator Wizard-eclipse Plug-in (used to generate a WSDL file for the service code and to parse the plug-in that generates the client code for the WSDL file):

Http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.6.2/axis2-eclipse-codegen-plugin-1.6.2.zip

To install the plugin:

I use MYECLIPSE10, take my environment as an example: Unzip the two plug-ins and put them under the D:\sdk\MyEclipse\MyEclipse 10\dropins directory, start the MyEclipse

File-new-other can find:

Iii. deployment of the Axis2 War

Unzip the downloaded Axis2-1.6.2-war.zip to get a Axis2.war file, drop this file into the Tomcat\webapps directory, start Tomcat
Visit Http://localhost:8080/axis2

See the following interface to deploy successfully.

Iv. Writing Service Code

Package com.xcy;/** * @author Siuon * @version 1.0 * @create 2012-7-19 PM 8:23:49 */public class AXIS2WB {/** * provides a say hello Service * @return */public string SayHello (string name) {return "Hello" +name;} /** * Provides a service to do addition * @param A * @param b * @return */public int Add (int a,int b) {return a + B;}}

Five. Package the service code into ARR files:

Eclipse Menu-New-file-other-axis2 Service archiver

class file location: The bin directory for the project where the AXIS2WB class was just written

Select Skip WSDL

If your AXIS2WB has a reference jar package, select it here. I didn't write it, so next.

Since we did not write service.xml, tick let it be generated automatically, next

Enter the service name (optional), class full name, load, next

Set the AAR file name and store the directory (I'm on the desktop)--finish:

When you're done, you can see a Axis2wb.aar file on the desktop, and we'll open it with WinRAR:

Did you feel familiar? Much like a jar package, we click on the Meta-inf directory to go in, you can see the plugin to our generated a service.xml, open to see (is not understand what the plugin did):

Vi. Release

Drop the Axis2wb.aar file to the Web-inf\services\ directory of the previously deployed AXIS2 app and restart Tomcat

Re-visit http://localhost:8080/axis2/Click Service

See that the announcement was successful

Vii. Generating Client code

You can generate the client code with JDK6 's own Wsimport tool: Java 6 development WebService

You can also generate client code from AXIS2 's Eclipse plug-in:

Eclipse Menu-file-new-other-axis2 Code Generator

Generate Java source code from a WSDL file: Generates Java code for WebService client based on WSDL. (Here, we choose this)
Generate a WSDL from a Java source file: Generates a WSDL file based on a Java sources (this source file is a Java source file intended to be published as a Web service, such as the Axis2wb.java in this demo).

After the code is generated, you will find an error because of the lack of the associated jar package.

Unzip the Axis2 downloaded in the first step Binary.zip all the jar packages below lib in the extracted directory and add them to the class path:

8. Invoking the Web service

 Packagetest;Importjava.rmi.RemoteException;ImportCom.xcy.Add;ImportCom.xcy.AddResponse;ImportCom.xcy.Axis2WB;Importcom.xcy.Axis2WBStub;ImportCom.xcy.SayHello;ImportCom.xcy.SayHelloResponse;/** * @authorSiuon *@version1.0 * @create 2012-7-19 PM 9:18:23*/ Public classTest { Public Static voidMain (string[] args)throwsRemoteException {//Creating Client ObjectsAXIS2WB AXIS2WB =Newaxis2wbstub (); //The new one calls the parameter SayHello required by the SayHello method, and sets the nameSayHello SayHello =NewSayHello (); Sayhello.setname ("Siuon"); //invoking the Web serviceSayhelloresponse Sayhelloresponse =Axis2wb.sayhello (SayHello); //get the results back .System.out.println (Sayhelloresponse.get_return ()); Add Add=NewAdd (); Add.seta (5); ADD.SETB (3); Addresponse Addresponse=Axis2wb.add (add);    System.out.println (Addresponse.get_return ()); }}

Results:

The above section is transferred from http://blog.csdn.net/xiaochunyong/article/details/7764683

In the generation of client code, found for WSDL2, the above tools encountered unresolved WSDL2 problems, so use their own methods, using the Wsdl2java tool

This tool needs to be installed

Use the command below to generate the stub class by entering the following command directly at the cmd command prompt

Wsdl2java-uri HTTP://127.0.0.1/AXIS2/SERVICES/MYTESTSERVICE?WSDL2-WV 2.0-p com.my.client-o D:\city-s-nobuildxml-s s Rc

Axis2 released WebService

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.