搭建AXIS2 webservice

来源:互联网 发布:comfortable zone 知乎 编辑:程序博客网 时间:2024/04/27 19:45
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, inputhttp://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!

原创粉丝点击