搭建AXIS2 webservice
发布时间:2020-12-17 00:56:26 所属栏目:安全 来源:网络整理
导读: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/,sta
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! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |