搭建AXIS2 webservice

1. download following archives:

2. unzip the last two zips to below directory for installing eclipse plug-in:

3. if plug-in installed success, you will see following effect:

4. unzip axis2.war from axis-1.6.2-war.zip to /tomcat/webapps/, start tomcat, input http://localhost:8080/axis2. you will see:


5. then, write a webservice example by yourself, code as belows:
public class HelloService {
public String sayHello(String name)
{
return name + "say : hello [axis2]";
}
}
put the class file of this to /tomcat/webapps/pojo/, if there is no pojo forder, please create one.
the you will find your service with: http://localhost:8080/axis2/services/listServices/

6. The reason we put class into pojo is there is code as below under /tomcat/webapps/axis2/WEB-INF/conf/axis2.xml:
<deployer extension=".class" directory="pojo" class="org.apache.axis2.deployment.POJODeployer"/>

7. try address: localhost:8080/axis2/services/HelloService/sayHello?name=jason, it will return a message as below:
<ns:sayHelloResponse><return>jasonsay : hello [axis2]</return></ns:sayHelloResponse>

8. client-side test code is:
package client;

import javax.xml.namespace.QName;

import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;




public class TestClient {
public static void main(String[] args) {

try{


RPCServiceClient client=new RPCServiceClient();

Options options = client.getOptions();

String address = " http://localhost:8080/axis2/services/HelloService";

EndpointReference epf = new EndpointReference(address);
options.setTo(epf);

QName qname = new QName(" http://ws.apache.org/axis2", "sayHello");

Object[] result = client.invokeBlocking(qname, new Object[]{"jake"}, new Class[]{String.class});

System.out.println(result[0]);


}catch (Exception e) {
e.printStackTrace();
}
}
}


over!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值