Developing a simple web Services

Source: Internet
Author: User

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

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.