Example of using axis to develop Web Service

Source: Internet
Author: User
1) download the axis package: http://ws.apache.org/axis/ first
2) The new web project name is:Axis

Copying the axis packageWebapps/axisAll files in the directory to the project directoryWebrootDirectory,
ThenRefreshEngineering

Create a new Java file named:HelloclientThe file content is as follows:

Import Java. util. list;
Import Java. util. arraylist;
public class Hello
{< br> Public String getname (string name)
{< br> return "hello" + name;
}< br> public list getlist ()
{< br> List list = new arraylist ();
list. add (0, "AA");
list. add (1, "BB");
list. add (2, "cc");
return list;
}< BR >}< br> now copy helloclient. java to the webroot directory and renamed it hello. JWS

Deploy the project and start the service

Start the browser and open the following link

Http: // localhost: 8080/axis/Hello. JWS? WSDL

3) create a test class:CodeAs follows:

 

Import java. util. arraylist;
Import java. util. List;

Import javax. xml. namespace. QNAME;
Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;
Public class testaxis
{
Public static void main (string [] ARGs)
{
Try
{
String endpoint = "http: // localhost: 9000/axis/Hello. JWS ";
Service = new service ();

Call call = NULL;
Call = (CALL) service. createcall ();

Call. setoperationname (New QNAME (endpoint, "getname "));
Call. settargetendpointaddress (New java.net. URL (endpoint ));
String STR = (string) Call. Invoke (new object [] {"jian "});
System. Out. println (STR );

// This is a complex data type. You need to configure call. invoke to convert it.
// Call. setoperationname (New QNAME (endpoint, "getlist "));
// Call. settargetendpointaddress (New java.net. URL (endpoint ));
// List = (arraylist) Call. Invoke (new object [] {});
// System. Out. println (list. Size ());

}
Catch (exception ex)
{
Ex. printstacktrace ();
}
}
}
Note the need for 5 jar packages: axis. jar, SAAJ. jar, jaxrpc. jar, commons-logging-1.0.4.jar, commons-discovery-0.2.jar

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.