微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

搭建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!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐