Axis1.4 framework implements webservice server and client, axis1.4webservice

Source: Internet
Author: User

Axis1.4 framework implements webservice server and client, axis1.4webservice

I. preparation in advance

Ii. Summary

Run the axis directory under the unzipped axis-1_4 \ webapps \ To the % atat_home %/Webapps/directory.
Enter http: // localhost: 8080/axis in the browser after tomcat is started.

Click the Validataion link in. The page displays information about the existing package and the missing package. Download all required packages as prompted, copy these class packages to the % atathome %/webapps/axis/WEB-INF/lib/directory and restart tomcat until the Error and Warning prompts are not displayed on the Validation page.

Axis supports three client access methods for web Services:

    • Dynamic Invocation Interface (DII)
    • Dynamic Proxy method
    • Stubs Mode

PS: I think it is inappropriate to see a lot of information as the three "deployment and development methods" of Web Servcie.

The following describes how to deploy and publish a web service using axis:

    • JWS-instant release
    • WSDD-custom release

3. JWS-instant release

JWS (Java WebService) is the simplest method. Axis allows you to change the extension of the source file of a common Java class to. jws, and then copy it to AXIS_HOME. In this way, Axis automatically compiles the. jws file,
And automatically add it to the Java Web Servie service. It is very simple and flexible, but the disadvantage of this method is that it can only be java source code, and the class cannot contain the package name. The procedure is as follows:

1. Use Eclipse or a text editor to compile a java class SayHello. java (this class does not include the package name)

 public class SayHello {     public String sayMsg(String name){         return "Hello: "+name;     } }

2. set the above class (SayHello. java) copy to the % tomcat_home %/webapps/axis/directory. You only need to copy the class source file (not the class) to this directory and rename it SayHello. jws

3. Open the browser and enter http: // localhost: 8080/axis/SayHello. jws to see:

Click the Click to see the WSDL link to view the generated wsdl.

4. Use Dynamic Invocation Interface (DII) to access the client as follows:

Package client; import org. apache. axis. client. call; import org. apache. axis. client. service; public class TestClient {/*** @ see axis framework implements a simple webService client to read the content of the webServicez server. If you have any questions, leave a message * @ param webUrl to set the called wsdl path, that is, the access path * @ param method sets the name of the called method * @ param parameters sets the parameter of the called method * @ author Deng longsheng (simpledls) * @ throws Exception */public static void readerWebserviceContent (String webUrl, String method, Object [] parameters) throws Exception {Service service = new Service (); Call call Call = (Call) service. createCall (); // call the method name to be called. setOperationName (method); // set the wsdl path of the call, that is, the access path call. setTargetEndpointAddress (webUrl); // parameters is a method transmission parameter. It must be of the same type and quantity as the called method body. String val = (String) call. invoke (parameters); System. out. println ("this is the information returned by the webservice server:/n" + val);}/*** @ param args * @ throws Exception */public static void main (String [] args) throws Exception {String webUrl = "http: // 192.168.1.121: 8080/axis/SayHello. jws "; String method =" sayMsg "; Object [] parameters = new Object [] {" axis web service "}; TestClient. readerWebserviceContent (webUrl, method, parameters );}}

 

4. WSDD (Web Service Deployment Descriptor) file Publishing Web Service

Package wsaxis. bean; public class UserBean {private String userName; // name private Integer age; // age public String getUserName () {return userName;} public void setUserName (String userName) {this. userName = userName;} public Integer getAge () {return age;} public void setAge (Integer age) {this. age = age ;}}

2. Create a MessageService. java class. The Code is as follows:

Package wsaxis; import wsaxis. bean. userBean; public class MessageService {/*** UserBean as the parameter */public String getBeanStr (UserBean bean) {return "You Name:" + bean. getUserName () + ", You Age:" + bean. getAge ();}}

3. Create a deploy. wsdd file, which is mainly used to generate the publishing file server-config.wsdd, click in the project: new --> other --> file content is as follows:

<deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/"    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">  <service name="MessageService" provider="java:RPC" style="rpc" use="encoded">    <parameter name="className" value="wsaxis.MessageService"/>    <parameter name="allowedMethods" value="*"/>         <typeMapping xmlns:ns1="http://wsaxis.michael.com" qname="ns1:userBean"             type="java:wsaxis.bean.UserBean"             serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"             deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"       />  </service></deployment>

Note: value = "wsaxis. MessageService". This MessageService is the MessageService. java you created. Make sure the path is correct!

Type = "java: wsaxis. bean. UserBean". This UserBean is the UserBean. java you created. Make sure the path is correct!

4. Create an undeploy. wsdd file to cancel the web service release. The method is the same as above. The content is as follows:

<undeployment    xmlns="http://xml.apache.org/axis/wsdd/">  <!-- Services from MessageService WSDL service -->  <service name="MessageService"/></undeployment>

5. copy the two compiled class files written above to the % atat_home %/axis/WEB-INF/class/directory (Note: copy the complete directory structure ), then, copy the two wsdd files to the % tomcat_home %/axis/WEB-INF/directory, open cmd and go to the % tomcat_home %/axis/WEB-INF/directory:

Java-Djava. ext. dirs = lib org. apache. axis. client. AdminClient-p 8080 deploy. wsdd

Java-Djava. ext. dirs = lib org. apache. axis. client. AdminClient-p 8080-s/axis/servlet/AxisServlet deploy. wsdd

Java-Djava. ext. dirs = lib org. apache. axis. client. AdminClient-lhttp: // localhost: 8080/axis/services/MessageService deploy. wsdd

Run the following command in CMD. If the command is successful, the system prompts the following:

Processing file deploy. wsdd
<Admin> Done processing </Admin>

(There may be a third failure, but it doesn't matter, mainly depending on whether the WEB-INF file has been generated under % atat_home %/axis/server-config.wsdd/directory), if there is this file, enter in the browser

Http: // localhost: 8082/axis/services/MessageService will see

 

 

I have been off work... continue with the new team !!

 

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.