AXIS2 Remote Call WebService example (Eclipse+axis)

Source: Internet
Author: User
Tags wsdl

Transferred from: http://www.cnblogs.com/lanxuezaipiao/archive/2013/05/10/3071584.html

After we publish the Web service on Tomcat or another application server, there are two ways to invoke the Web service:

1, through the browser call, return the canonical XML file
2, through the client program call, return results can be customized format


Next, I use Eclipse Java EE as a development tool to demonstrate a simple example of an axis calling WebService
The first call to see my other blog post: http://www.cnblogs.com/lanxuezaipiao/archive/2013/05/10/3072216.html
The steps are as follows:

preparation: download AXIS2 latest version (official download: http://axis.apache.org/axis2/java/core/download.cgi), import the Axis class library, the download package. The jar files in the/lib/directory are copied to the Lib file under the web-inf of the project.

List of required jar packages:

First step : Create a new Web project with the project name WebServiceTest

Step Two : Create a simple Helloservice.java class that prints the string:

1  PackageCom.sinosoft.webservice;2 3  Public classHelloService {4     /**5 * functions without parameters6      * 7      * @returnreturns a Hello string8      */9      PublicString SayHello () {Ten         return"Hello"; One     } A  -     /** - * Functions with parameters the      *  -      * @paramname - * Name -      * @returnreturns a welcome word with a name +      */ -      Publicstring Sayhellotoperson (string name) { +         if(Name = =NULL|| Name.equals ("")) { AName = "Nobody"; at         } -         return"Hello" +name; -     } -}

Step three : Right-click the helloservice.java---web Services---Create Web service. Click Next ... finish, at which point the WebContent directory is found to generate a WSDL directory, There is a helloservice.wsdl in the directory

Fourth Step : Test Web Service: Right-click helloservice.wsdl---Web Services---Test with Web services Explorer---Click on the method name CONNECTSTR----input parameter XXX---point go. The console output hello,xxx will be found, indicating that the test was successful, WebService no problem

Fifth Step : Write the client call class HelloWorldTest, using AXIS2 Remote call HelloWorld (in order to reflect the remote call, create a new project, named Axistest), the code is as follows:

1  PackageCom.sinosoft.webservice;2 3  Public classHelloService {4     /**5 * functions without parameters6      * 7      * @returnreturns a Hello string8      */9      PublicString SayHello () {Ten         return"Hello"; One     } A  -     /** - * Functions with parameters the      *  -      * @paramname - * Name -      * @returnreturns a welcome word with a name +      */ -      Publicstring Sayhellotoperson (string name) { +         if(Name = =NULL|| Name.equals ("")) { AName = "Nobody"; at         } -         return"Hello" +name; -     } -}

Sixth step : Test: HelloWorldTest---Run as---Java application, if you find the console output Hello Weiyongle correctly, the test is successful

Note : 1, when setting the method name and parameter name, must be consistent with the called WebService
2, the passed parameters need to be encapsulated in an object array
3, the remote call path endpoint for the fourth step test endpoints

AXIS2 Remote Call WebService example (Eclipse+axis)

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.