WebService工具类

前端之家收集整理的这篇文章主要介绍了WebService工具类前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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;  
  
    }  
}  

猜你在找的WebService相关文章