1.jws Mode Instance
Write a service class
public class Helloworld{public string SayHello (string name) { return "axis" +name;}}
Rename this class's source file Helloworld.java to Helloworld.jws and copy it to the Tomcat/webapps/axis directory to start Tomcat
Write the client program, call the service above
Package Com.liyang.axis.client;import Java.rmi.remoteexception;import Javax.xml.rpc.parametermode;import Javax.xml.rpc.serviceexception;import Org.apache.axis.client.call;import Org.apache.axis.client.service;import Org.apache.axis.encoding.xmltype;public class HelloWorld {/** * @param args * @throws serviceexception * @throws Remo Teexception */public static void Main (string[] args) throws Serviceexception, remoteexception { String Endpoint = "Http://localhost:8080/axis/HelloWorld.jws"; String name= "Liuyang"; Org.apache.axis.client.Service service=new Service (); Call Call= (call) Service.createcall (); Call.settargetendpointaddress (endpoint); Call.setoperationname ("SayHello"); Call.addparameter ("param1", xmltype.xsd_string,parametermode.in); Call.setreturntype (xmltype.xsd_string); String set= (String) Call.invoke (new Object[]{name}); SYSTEM.OUT.PRINTLN (set);}}
Run, both can get results run
2.WSDD mode
Write a service class
Compile this class. and copy the class file to the Tomcat/webapps/axis/web-inf/classes directory
3. Writing the document DEPLOY.WSDD
public class Helloworld{public String <pre name= "code" class= "HTML" ><?xml version= "1.0" encoding= "UTF-8"?> <deployment xmlns= "http://xml.apache.org/axis/wsdd/" xmlns:java= "http://xml.apache.org/axis/wsdd/providers/j Ava "> <globalConfiguration> <parameter name=" AdminPassword "value=" admin "/> <parameter name=" Attachments. Directory "value="./attachments "/> <parameter name=" attachments.implementation "value=" Org.apache.axis. Attachments. Attachmentsimpl "/> <parameter name=" Sendxsitypes "value=" true "/> <parameter name=" sendMultiRefs "value=" True "/> <parameter name=" sendxmldeclaration "value=" true "/> <parameter name=" axis.sendminimizedelements "Value=" true "/> <requestFlow>
SayHello (String name) {return "axis" +name;}}
Note Modify the contents of the service above
Open the command line and switch the directory to the directory where the DEPLOY.WSDD is located.
Running: Java org.apache.axis.client.AdminClient DEPLOY.WSDD
Get the following results:
Processing file DEPLOY.WSDD
<admin>done processing</admin>
Complete deployment
Writing client Calls
Package com.liyang.axis.client;
Import java.rmi.RemoteException;
Import Javax.xml.rpc.ParameterMode;
Import javax.xml.rpc.ServiceException;
Import Org.apache.axis.client.Call;
Import Org.apache.axis.client.Service;
Import Org.apache.axis.encoding.XMLType;
public class HelloWorld {
/**
* @param args
* @throws serviceexception
* @throws RemoteException
*/
public static void Main (string[] args) throws Serviceexception, RemoteException {
String endpoint= "Http://localhost:8081/axis/services/MyService";
String name= "Liuyang";
Org.apache.axis.client.Service service=new Service ();
Call Call= (call) Service.createcall ();
Call.settargetendpointaddress (endpoint);
Call.setoperationname ("SayHello");
Call.addparameter ("param1", xmltype.xsd_string,parametermode.in);
Call.setreturntype (xmltype.xsd_string);
String set= (String) Call.invoke (new Object[]{name});
SYSTEM.OUT.PRINTLN (set);
}
}
Developing a simple web Services