java webservice AXIS

1. eclipse axis 插件下载地址   http://archive.apache.org/dist/ws/axis2/tools/1_4_1/

  一个是代码生成插件   axis2-eclipse-codegen-wizard

  一个是服务打包插件  axis2-eclipse-service-archiver-wizard

2. 编写service 服务内容。简单的演示有参数和无参数的调用方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package com.csc.joy;
 
public class Axis2Service {
 
    public String sayHello() {
        return "Hello World!";
    }
 
    public String sayHelloToPerson(String name) {
        if (name == null || name.equals("")) {
            name = "nobody";
        }
        return "Hello World!" + name;
    }
}

 

 

3.  调用service的java代码 ,直接运行就行,注意此时要打开tomcat服务才行。

java webservice AXIS
package com.csc.joy.client;

import java.rmi.RemoteException;
import java.util.Iterator;

import javax.xml.namespace.QName;

import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

public class ClientTest {

    public static void main(String[] args) throws RemoteException {
        //调用方法1        
        RPCServiceClient rpcServiceClient = new RPCServiceClient();
        Options options = new Options();
        options.setTo(new EndpointReference("http://localhost:8080/axis2/services/Axis2Service"));
        options.setAction("urn:sayHelloToPerson");
        rpcServiceClient.setOptions(options);
        OMElement element = rpcServiceClient.invokeBlocking(new QName("http://joy.csc.com", "sayHelloToPerson"),new Object[]{"sss"});
        Iterator values = element.getChildrenWithName(new QName("http://joy.csc.com","return"));
        while(values.hasNext()){
            OMElement omElement = (OMElement) values.next();
            System.out.println(omElement.getText());
        }
    }
}
java webservice AXIS

 

 

 

参考: http://wenku.baidu.com/link?url=Zn-PuwUus3R6y4ekbKLJRdm50fN_hyX3WosevBvrdX8-y2dov7sCnwAX8NxELTM58HGar4KA6xXwuY2jju6nqTqy7dY2zERzmud9kTmuv-q

java webservice AXIS

上一篇:js中替换字符串


下一篇:前端代码标准最佳实践:CSS