zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    gson和fastjson
    Hive和HBase的区别
    mac 比较两个文件
    mysql 查找在另一张表不存在的数据
    mysql 根据一张表更新另一张表
    shell调试
    目标
    百度在线面试总结
    20170109| javascript记录
    php-fpm问题
  • 原文地址:https://www.cnblogs.com/zyy258963/p/3528584.html
Copyright © 2011-2022 走看看