WebService工具类

来源:互联网 发布:股票自动止损 知乎 编辑:程序博客网 时间:2024/06/13 15:12
import org.apache.axis.client.Call;import org.apache.axis.client.Service;import org.apache.axis.utils.StringUtils;/** * 功能描述:WebService 远程调用工具 *  */public class WebServiceClient {        public static void main(String[] args) throws Exception {        String url = "http://ip:port/oms/createOrder.service";        String method = "createOrder";        EncryptedUtils encryptedUtils = new EncryptedUtils();        String companyCode = encryptedUtils.encode("test");        String vercode = encryptedUtils.encode("test");        String orderXml = encryptedUtils.encode("test");        String[] parms = new String[]{ companyCode, vercode, orderXml };        WebServiceClient webClient = new WebServiceClient();        String svrResult = webClient.CallMethod(url, method, parms);        System.out.println("===========>"+svrResult);    }      public static String CallMethod(String url, String method, Object[] args) {        String result = null;            if(StringUtils.isEmpty(url))          {              return "url地址为空";          }            if(StringUtils.isEmpty(method))          {              return "method地址为空";          }            Call rpcCall = null;              try {              //实例websevice调用实例              Service webService = new Service();            rpcCall = (Call) webService.createCall();            rpcCall.setTargetEndpointAddress(new java.net.URL(url));            rpcCall.setOperationName(method);            //执行webservice方法            result = (String) rpcCall.invoke(args);          } catch (Exception e) {              e.printStackTrace();          }          return result;        }  }  


原创粉丝点击