Use Apache axis to implement Web Service (5)

Source: Internet
Author: User

5. Access web service using stubs

The willingness of stubs in software is "stubs" and "piles", which is a proxy created in the system to hide remote calls. The use of stubs encapsulates the complex details of remote calls. Other classes can use the remote functions through stubs just like local classes.

Here, we still use the established helloworld. JWS to describe how to use stubs.

Axis provides the WSDL tool to automatically generate stubs. Wsdl2jav uses the Web Service Description Language (WSDL) file of web service to automatically generate Java stub classes.

Run Java org. Apache. axis. WSDL. wsdl2java-P client http: // localhost: 8080/axis/helloworld. JWS? WSDL

Make sure that all jar packages in the axis/lib directory are included in the classpath. After successful execution, a client directory is generated under the current directory, which contains four Java class files:

Helloworld. Java
Helloworldservice. Java
Helloworldservicelocator. Java
Helloworldsoapbindingstub. Java

This is the stubs that can access helloworld locally. You can access helloworld through this stubs:

Import client .*;

Public class testhelloclient ...{
Public static void main (string [] ARGs )...{
Try ...{
Helloworldservice service = new client. helloworldservicelocator ();
Helloworld client = service. gethelloworld ();
String retvalue = client. sayhello ("Brookes ");
System. Out. println (retvalue );
} Catch (exception e )...{
System. Err. println ("execution failed. Exception:" + E );
}
}
}

Execute this program and you will get the results returned by the Web Service:

Hello Brookes, welcome to my web service.

Axis also provides a java2wsdl tool to automatically generate a WSDL file from a Java class. You can also use this command to generate the WSDL file, for example:

Java org. Apache. axis. WSDL. java2wsdl-ohelloworld. WSDL-lhttp: // localhost: 8080/axis/service/urn: helloworld-nhelloworld Brookes. helloworld

Then, use the generated helloworld. WSDL file to generate stubs.

Java org. Apache. axis. WSDL. wsdl2java helloworld. WSDL-P Client

There is a lot of information about how to use the axis command line tool on the Internet, such as Baidu/Google.

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.