java调用外部webservice接口的方法

import java.net.URL;


import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;


import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;



public class CompanyCredit {
/**
* 通过参数列表信息
* @param
* @return
*/
public static JSONArray getMethod(String three){
JSONArray josnArray = null;
try {
String url = "http://***************************************************?wsdl";
String targetnamespace = "http://***************************";
String method = "*********************";
Service sv = new Service();  //new 一个服务  
       Call call = (Call) sv.createCall();  //创建一个call对象  
       call.setTargetEndpointAddress(new URL(url));  //设置要调用的接口地址以上一篇的为例子  
       call.setOperationName(new QName(targetnamespace,method));  //设置要调用的接口命名空间和方法  
       call.addParameter("customCode", XMLType.XSD_STRING,ParameterMode.IN);//设置参数名  第二个参数表示String类型,第三个参数表示入参
       call.addParameter("customLisence", XMLType.XSD_STRING,ParameterMode.IN);//设置参数名  第二个参数表示String类型,第三个参数表示入参
       call.addParameter("qymc", XMLType.XSD_STRING,ParameterMode.IN);//设置参数名  第二个参数表示String类型,第三个参数表示入参  
       call.setReturnType(XMLType.XSD_STRING);//返回参数类型  
       
       String one= "*********************";  //第一个参数
       String two= "************************";//第二个参数
       //开始调用方法
       String result = (String) call.invoke(new Object[]{one,two,three});  
       System.out.println(result);//打印字符串   
       josnArray = JSONArray.fromObject(result);
        } catch (Exception e) {  
            System.err.println(e.toString());  
        }  
return josnArray;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值