axis调用webservice的简单方法

package com.service;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class test2 {
 public static void main(String args[]){ 	
         String helloURL = "http://localhost:8889//services/HrmService";
         try {
             //以下都是套路 
             Service service = new Service();
             Call call = (Call)service.createCall();
             call.setTargetEndpointAddress(helloURL);
             call.setOperationName("checkUser");//WSDL里面描述的接口名称
             call.addParameter("in0", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);//接口的参数
             call.addParameter("in1", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);//接口的参数
             call.addParameter("in2", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);//接口的参数
             
             call.setReturnType(org.apache.axis.encoding.XMLType.XSD_BOOLEAN);//设置返回类型  
            
             //给方法传递参数,并且调用方法
             Object result = call.invoke(new String[]{"127.0.0.1","ywy","1"});
             System.out.println((Boolean)result);
             
          } catch (Exception e) {
              e.printStackTrace();
          }
          
	 } 
}
  •  注意:url不能带wsdl,否则会报错
posted @ 2015-01-09 14:38  Json_wangqiang  阅读(1102)  评论(0编辑  收藏  举报