Axis1.4 develop a webservice client (Quick Start)-based on jdk1.4 and axis1.4jdk1.4

Source: Internet
Author: User

Axis1.4 develop a webservice client (Quick Start)-based on jdk1.4 and axis1.4jdk1.4

Preface:

For the client, after the server is developed, the client only needs to call it. Here we will talk about generating the code used by the client based on the service access address (I heard there are several call methods, but the most common method is the stub method, it seems that I am talking about this method, but I have not studied it in depth. Haha, learn how to use it first)

1. Enter the service access address in the browser, for example, http: // localhost: 8080/test_axis3_stub/services/sayHello? Wsdl to ensure that the service can be accessed normally.

2. Compile A. bat file to generate java client code. The file name can be retrieved as needed. The content is as follows:

set Axis_Lib=D:\myEclipse10_WS\job\test_axis3_stub\WebRoot\WEB-INF\lib set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib% set Output_Path=D:\my set Package=edu.hue.stub%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p%Package% http://localhost:8080/test_axis3_stub/services/sayHello?wsdl

Copy and paste the above file to your file, and then explain it a little bit. Axis_Lib: This is your axis. jar storage path. Generally, for convenience, we can directly write the path of your project to lib, because your jar package is placed here; Output_Path: it is the path to generate the java client code. You can specify the path here, for example, D: \ my, provided that the folder my is under your D Drive; finally, replace the above access link with the link of the service you want to access. Here, my website is http: // localhost: 8080/test_axis3_stub/services/sayHello? Wsdl

Then, double-click to run this. the bat file can generate the java client code under D: \ my. Oh, by the way, maybe you are just like me. I don't know how to create a bat file. Let's just talk about it. You create a notepad file, write the content, and save it as my. bat. Note that the storage type must be changed to all files. And save it. It becomes the. bat file.

3. copy and paste the generated java client code into your project.

4. Create a client class with the following content:

Package edu. hue. client; import java. rmi. remoteException; import edu. hue. stub. sayHelloImpl; import edu. hue. stub. sayHelloImplService; import edu. hue. stub. sayHelloImplServiceLocator; public class MyClient {public static void main (String [] args) throws Exception {// gets the service Set SayHelloImplService service = new SayHelloImplServiceLocator (); // obtain the service SayHelloImpl client = service. getsayHello (); // call the service method to pass the parameter String result = client. say ("smelly little mosquito"); System. out. println (result );}}

Here, the collection of services is new according to the java class you just generated. Pay attention to the observation. Generally, this collection ends with a Service, and you can simply create this class; get the Service, write directly. the prompt is displayed. You can select the one that meets the service class you want to call. The method for calling the service is also used to write the client. then, based on the prompts, you can determine which method you want to call.

5. Right-click and run. Success ~~~~

Here we all talk about how to quickly use asix1.4 to develop a webservice. It involves more complex parameter transfer. For example, if the passed parameter is a bean, you need to study it on your own.

 

 

Related Article

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.