本帖最后由 solove394324947 于 2010-10-12 12:29:20 编辑

解决方案 »

  1.   

    网上有2种实现方式..建议楼主试试第二种方式.
    public class Client {
        //    public static void main(String[] args) throws RemoteException, ServiceException, MalformedURLException {
            /* **************** 调用方法1 *********************** */
            RPCServiceClient rpcClient = new RPCServiceClient();
            Options opt = new Options();
            opt.setTo(new EndpointReference("http://localhost:8080/axis2/services/Hello")); //服务地址
            opt.setAction("urn:hw"); //方法
            rpcClient.setOptions(opt);
            OMElement element = rpcClient.invokeBlocking(new QName("http://com", "hw"), new Object[]{null}); //null表示没有参数传递        Iterator values = element.getChildrenWithName(new QName("http://com", "return")); //return表示有返回值
            while (values.hasNext()) { //遍历出获取的数据
                OMElement omElement = (OMElement) values.next();
                System.out.println(omElement.getText());
            }         /* **************** 调用方法2 *********************** */
            String method = "hw";
            Service service = new Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(new java.net.URL("http://localhost:8080/axis2/services/Hello"));
            call.setOperationName(new QName("http://com/", method));
            call.setUseSOAPAction(true);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
            call.setSOAPActionURI("http://com/GetServerList");
            String k = (String)call.invoke(new Object[]{}); //因为返回值是String类型,所以这里调用的返回值也是String类型
            System.out.println(">>> "+k); //返回值输出    }
    }