#AXIS2 Release webservice#

Source: Internet
Author: User
Tags custom name wsdl

Axis2 is a plugin that can implement WebService, which can be published using this plugin webservice

1: You can use this plugin to publish webservice, you can see the URL: http://clq9761.iteye.com/blog/976029/====== personal feeling is generally not suitable for us to do the project time use

2: Here we introduce the AXIS2 package into a Web project and run the Web project to publish webservice=====

This is what we often use, such as want you to write a WebService client, how do you want to do? A basic idea is to create a Web project and then introduce a AXIS2 package that uses AXIS2 to implement a webservice.

To use Axis2 to implement WebService, there are a few things to do:

1: Create a web project, = = = = To create a web service = = = This is all the words of my wife. It's actually creating a Web project.

2: To introduce the required folders into the Lib folder of the Web project

3: Create Service.xml file =====axis2 Publish WebService XML file that needs to be configured

4: Configure Web-Engineering's XML, scan Axis2 's Service.xml file

5: Write the corresponding class to implement

Then run the written Web project, execute the path on the Web page can be, in fact, follow the steps are very simple, the following is the detailed introduction of each step

First step: Create a Web project

Step two: Introduce the required clip pack

There's a problem. Where does the package come from, Baidu can not be a one-off, to Axis of the official website to download
Plugin Download URL: http://axis.apache.org/axis2/java/core/download.html

Note Here is the version of the package, the official Web download may be different from the picture shown in this chapter, this does not have to tube, the name of the line

If you can't change it, try =============== first so we can copy all the required packages to the Lib of the Web project.

Step three: Create a service.xml file and see

Create a Services folder under Web-inf and then create a------conf----meta-inf----services.xml

The contents of Services.xml are as follows:

=================services.xml Content starts =========================

<?xml version= "1.0" encoding= "UTF-8"?>
<service name= "Testservice" > <!--Designated service name, freely defined
<description> Test axis2webservices</description><!--Service description, can write not write-to
<!--Specify the CLASSPATH to be published--
<parameter name= "ServiceClass" > <!--custom name-->
Com.axiswevservice.test.TestService <!--write Classpath--
</parameter>
<!--class, there are other ways to write a operation label--
<operation name= "Test" > <!--class method name--
<messagereceiver class= "Org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
</service>
<!--http://localhost:8080/testaxis2webservice/services/Testservice?wsdl--

=================services.xml Content End =========================

http://localhost:8080/testaxis2webservice/services/Testservice?wsdl

Note: The path above is the WSDL path to run after building the Web project
1: Specify the service name ===== is the WSDL path to run? and/or between that part = = = You can say that the specified service name is part of the WSDL path

2: The role of the service description = = = This does not need to Tube = = = is equivalent to a comment, say what you want to publish the WebService is what?

3: Specify the Classpath to be published ====== you're going to make that class webservice.

4: Methods inside the class, there are other ways to write a operation tag ======= Configure the method you write in the class

Fourth step: Configure Web. xml
=================web.xml Content starts =========================

<?xml version= "1.0" encoding= "UTF-8"?>
<web-app xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id= "Webapp_ ID "version=" 3.0 ">
<display-name>testaxis2webservice</display-name><!--project name, automatically generated when the project is created--
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

</web-app>

=================web.xml Content End =========================

Fifth step: Write the Publishing class

============================ writing class began to ======================

Package com.axiswevservice.test;

public class Testservice {

public string test (string test) {
Return "Test axis2webservice:" +test;
}

}

========================== writing end of class =========================

Class write simple point, now just test no need to write complex, just write a class, class write a method
After writing here, it is necessary to correspond with the above Service.xml, service.xml inside the class path, the method name should be the same as written here

After writing it, this is the project's structure chart as follows

Run the project in ECLIPCE

Then enter HTTP://LOCALHOST:8080/TESTAXIS2WEBSERVICE/SERVICES/TESTSERVICE?WSDL on the Web page

The composition of the path: IP and port number configured in Tomcate + project name + Web. XML config <url-pattern> + service.xml service name specified inside

The results of the operation are as follows:

This succeeds, using AXIS2 to implement the WebService server, so that a client call can be written

=====================================================================================

The interface to write client-side calls to the service is not getting through,

We can use SOUPUI this software to test the server side, but also can write their own code testing

Here we write ourselves: How to do it? Very simple, need to do as follows:

1: Build a Java project------Create a Java project

2: Introduction of the clip Pack

3: Write a test class

=========================== Start ==================================

The first step: Create a Java project ====== is to create a Java projects, our projects are generally divided into Java projects, Web projects, MAVEN projects ...

The second step: the introduction of the package, the introduction of the method and the above write service side introduced the same, but more than two clip pack Httpcore-4.4.4.jar,commons-codec-1.3.jar

These two clamps can also be found under the AXIS2 's plug-in Lib

Step three: Writing test classes

In fact, it is to build a Java project, the writing of the Web project to copy the folder to the Java project, in the Axis2 from the solution of the pressure of the Lib add a few two packets, write a kind of test on the line

====================== Test class Start =======================

Package testwebserver;

Import Javax.xml.namespace.QName;

Import Org.apache.axis2.AxisFault;
Import org.apache.axis2.addressing.EndpointReference;
Import org.apache.axis2.client.Options;
Import org.apache.axis2.rpc.client.RPCServiceClient;

public class Test {

public static void Main (string[] args) {

try {
The native Tomcat port defaults to 8081, and the parameter is part of the WSDL URL
EndpointReference Targetepr = new EndpointReference ("Http://localhost:8081/testaxis2webservice/services/Testservice");
Rpcserviceclient sender = new Rpcserviceclient ();
Options options = Sender.getoptions ();
Options.settimeoutinmilliseconds (2*20000l);//Time-out 20s
Options.setto (TARGETEPR);
/**
Parameters
* 1: TargetNamespace path of Xs:schema label after executing WSDL on Web page
* <xs:schema targetnamespace= "http://test.axiswevservice.com" >
* 2:<xs:element name= "Test" > ====== the value of name in this tag
*
*/
QName QName = new QName ("http://test.axiswevservice.com", "Test");
String str = "Client invocation succeeded"; The entry of the method
object[] param = new OBJECT[]{STR};
class<?>[] types = new Class[]{string.class}; This is for the value of the rebate type
/**
* The Invokeblocking method of the Rpcserviceclient class called the method in WebService.
* Invokeblocking method has three parameters
* The type of the first parameter is a QName object that represents the method name to invoke;
* The second parameter represents the parameter value of the WebService method to be called, and the parameter type is object[];
* The third parameter represents the class object of the return value type of the WebService method, with a parameter type of class[].
*
* When the method has no arguments, the second parameter value of the Invokeblocking method cannot be null, but new object[]{} is used.
*/
object[] Response1 = sender.invokeblocking (QName, param, types);
System.out.println (Response1[0]);
} catch (Axisfault e) {
TODO auto-generated Catch block
E.printstacktrace ();
}

}
}

====================== Test class End =========================

This is a Java project, directly written in the main method, directly run the main method can be,

Note: The service you write here is always up, and the test call here can be tuned to see:

Summary: If all is measured, we have to understand the time

1:axis2 What clips are needed to implement webservice, and where are the packages coming from?

What to look for, the folder is from the official website of Axis2, the official website has a ... bin.zip file, unzip the file, there is a Lib folder, there are all the clips

2: How can I use Axis2 to publish a webservice,

A service.xml configuration file that needs to be axis2, we want to make sure that the configuration file is scanned when the project starts, and that it is consistent with the class/method being written

Then the program will be service.xml inside the configuration of the classes and methods to make a Webserce release,

We are here to introduce service.xml into a Web project, using Web-engineering's website. XML to scan the Service.xml file, when running this web project The program will be service.xml inside the configuration into a Webservce service released, as long as this web project has been up, we can invoke the published service

3: How to write the method in the class to be published

Method has a return value and an entry parameter, regardless of the complexity of the writing method, the format is the same

4: How did the client write it?

The client is writing a Java project to write a class test on the line, the folder to see above, call the code to take a good look at

#AXIS2 Release 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.