[Reprint] axis study notes

Source: Internet
Author: User

From: http://blog.csdn.net/ronghao100/archive/2005/06/08/390530.aspx

Series: http://www.blogjava.net/RongHao/archive/2007/06/12/123644.html

The day before yesterday, I was told to use the soap Web Service to develop a client program to interact with ERP in the enterprise. In the evening, hurry up to find relevant information and try again to get to know soap. It's really not easy for programmers to do this. It seems that they have to keep learning new things and be eliminated accidentally: (but learning is also a very interesting thing. Let's get started.

I. Software Environment

1. axis-1_2 (extract the latest axis-bin-1_2.zip from the apache)

2. tomcat5.0

3. jdk5.0

Ii. Related Configuration

1. Under your % atat_home % \ common \ Lib, add three packages: Activation. jar, mail. jar, and tools. jar.

2. environment variable settings

Axis_home is the directory that axis-bin-1_2.zip unzipped (my files are in the F: \ soap \ axis-1_2)

Axis_lib: % axis_home % \ Lib

Axisclasspath is % axis_lib % \ axis. jar; % axis_lib % \ commons-discovery-0.2.jar; % axis_lib % \ commons-logging-1.0.4.jar; % axis_lib % \ jaxrpc. jar; % axis_lib % \ SAAJ. jar; % axis_lib % \ log4j-1.2.8.jar; that is, import the jar files used in % axis_lib %

Iii. Experiment

Find the axis folder under % axis_home % \ webapps, copy it to % tomcat_home % \ webapps, and start

Tomcat: Open the browser to access http: // localhost: 8080/axis/. The following page appears, indicating that your configuration is successful. Very easy :)

 

4. Release our first program

The first program simply returns Hello world!

Helloworld. Java

Public class helloworld {
Public String sayhello ()
{
Return "Hello world! ";
}
}

Our first release method:

Copy helloworld. Java to % tomcat_home % \ webapps \ axis and rename it helloworld. JWS. Then axis will release it. Now write a client program to access:

Testclient. Java

Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;

Import javax. xml. rpc. parametermode;

Public class testclient
{
Public static void main (string [] ARGs) throws exception {

String endpoint = "http: // localhost/:" + "8080" + "/axis/helloworld. JWS"; // specify the Service Location

Service = new service (); // You must create a service instance!
Call call = (CALL) service. createcall (); // You must create a call instance!

Call. settargetendpointaddress (New java.net. URL (endpoint); // set the service location for the call.

Call. setoperationname ("sayhello"); // note that the method name is the same as that in helloworld. Java !!

String res = (string) Call. Invoke (new object [] {}); // return string, no input parameter

System. Out. println (RES );
}
}

My test is in jbuilder2005. Note that the project needs to import its own axis package (of course, replace the JAR file with it). You can see that the program returns "Hello world! "

It can be seen that releasing a service in axis is actually very easy. This is because this service is very simple: Below we will introduce the second release method, which is commonly used.

Our second release method:

1. Compile helloworld. Java into helloworld. Class and put it in % tomcat_home % \ webapps \ axis \ WEB-INF \ Classes

Lower

2. Create a New deploy. WSDD file under % atat_home % \ webapps \ axis \ WEB-INF, that is, the soap Service Release description file

Deploy. WSDD

<Deployment xmlns = "http://xml.apache.org/axis/wsdd/" xmlns: Java = "http://xml.apache.org/axis/wsdd/providers/java">
<Service name = "helloworld" provider = "Java: RPC">
<Parameter name = "classname" value = "helloworld"/>
<Parameter name = "allowedmethods" value = "sayhello"/>
</Service>
</Deployment>

In dos, convert the directory to % atat_home % \ webapps \ axis \ WEB-INF. command:

Java-CP % axisclasspath % org. Apache. axis. Client. adminclient deploy. WSDD

You will find an additional server-config.wsdd file in the directory, which is the axis configuration file, which will be found in all the service release descriptions later. (Of course, you can modify it directly without writing deploy. WSDD) then open the browser http: // localhost: 8080/axis/servlet/axisservlet, and you will see that your service has been published.

Use the client program for access: (note the difference with the above !!)

Helloclient. Java

Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;

Public class helloclient
{
Public static void main (string [] ARGs) throws exception {

String endpoint = "http: // localhost/:" + "8080" + "/axis/services/helloworld"; // note! The difference is only here !!

Service = new service ();
Call call = (CALL) service. createcall ();
Call. settargetendpointaddress (New java.net. URL (endpoint ));
Call. setoperationname ("sayhello ");

String res = (string) Call. Invoke (new object [] {});

System. Out. println (RES );
}
}

Well, I believe you have a general understanding of axis. Next will involve passing parameters, JavaBean object, and axis security issues, Next time let's talk about it :) also welcome and me, a happy Java programmer, contact :) ronghao100@hotmail.com

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.