加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

WebService工具类

发布时间:2020-12-16 21:42:33 所属栏目:安全 来源:网络整理
导读: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 Exc
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;  
  
    }  
}  

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读