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 服务内容。简单的演示有参数和无参数的调用方法

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服务才行。

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());
        }
    }
}

 

 

 

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

转载于:https://www.cnblogs.com/zyy258963/p/3528584.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值