Axis2 is an open-source WebService framework of the Apache Foundation.
This open-source framework can be used to publish some WebService services. For example, weather forecasts for some websites, interconnection between two systems, and cross-platform Data Interaction (Java ,. net, C #, because it transmits XML packets based on the HTTP protocol of soap, this open-source framework is cross-language .)
As stated on the official website
Preparations: tomcat7, jdk1.6, ant, eclipse, and axis2
Download to the Apache official website to download binary
Perform the following operations to ensure that ant and JDK environment variables have been installed.
Download to the local device and run ant
Ant will produce war in the Dist directory. Put war in Tomcat's webapps and start it.
There are multiple publishing methods. I use the following method. (Another method is to produce AAR files and WSDD files)
Create a new web project in eclipse, copy the conf, modules, services under the WEB-INF folder in the downloaded axis2 to your project's WEB-INF
Then create a folder under the Services Directory named project name, create a META-INF file under this folder, and then create a services. xml
The directory structure is as follows:
There should be many ways to write sevices.
Class for publishing websevice. There are two methods. One has a return value and the other is empty.
package com.test.axis;import java.util.HashMap;import java.util.Map;public class HelloFriend {Map<String,String> testMap = new HashMap<String,String>();public String sayHello(String name){if(testMap.get(name)!=null){return "hello,"+testMap.get(name);}return "welcome ,null";}public void test(String key,String value){testMap.put(key, value);System.out.println("test void method");}}
Define in services. xml
<service name="HelloWorld" scope="application" targetNamespace="http://axis.samples/"> <description> HelloWorld Service </description> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </messageReceivers> <schema schemaNamespace="http://axis.samples/xsd"/> <parameter name="ServiceClass">com.test.axis.HelloFriend</parameter></service>
Note that the bold part above is different. If there is no return value, the first method is used. If there is a return value, the second method is used.
Then deploy it to Tomcat to start.
Http: // localhost: 8080/testaxis/services/helloworld? WSDL
The release is complete and the page access is successful.
Next we will test each method:
1. If a returned value is tested first, the result is as follows:
2. The test has no return value.
In this case, MAP has a value.
Then let's take a look at the result of method 1.
The tests above are very simple.
There are also a lot of code tests on the Internet. I will not talk about them here. If you are interested, you can search online.
In fact, there are a lot of advanced content in websevice, such as the returned value of list <user>, MAP, JSON, and so on, and transfer attachments.
How can we handle big data transmission?
If you have any experience in this area, let us know first. Thank you.