1.使用xfire
public void list(){
//MdPsBaseInfoListService 接口类
Service serviceModel = new ObjectServiceFactory().create(MdPsBaseInfoListService.class);
XFire xfire = XFireFactory.newInstance().getXFire();
XFireProxyFactory factory = new XFireProxyFactory(xfire);
//接口调用的URL
String serviceUrl = "http://192.168.1.231:8080/wqms/services/MdPsBaseInfoListService";
MdPsBaseInfoListService client = null;
try {
client = (MdPsBaseInfoListService) factory.create(serviceModel, serviceUrl);
//调用方法,传入需要的参数,接收返回值
String s = client.getBaseInfoXml("合肥金鹰纸业有限公司", "", "");
System.out.println(s);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
需要知道接口类的名字,然后写一个接口类。
2.使用axis2
package com.thunisoft.hlwzbdb.mgr.business.ajgl.record;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.commons.lang.StringUtils;
import com.thunisoft.hlwzbdb.mgr.business.ajgl.record.bean.AjBean;
import com.thunisoft.hlwzbdb.mgr.business.ajgl.record.bean.RecordingResult;
/**
* Ajgl调用 WebService接口类
* 处理返回的数据
*/
public class WsCallerAj {
private static String wsdl = "http://172.16.7.226:5080/susong51/services/ajxxWebService/getAjList?jsonStr=";
/**
* 调用webservice接口
*
*/
public static String getInterface(String corpId,int page,int limit,
String cAh,String ajMc,String dsrMc,String cbrMc){
JSONObject req = WsCallerAj.parseStr2Json(corpId, page, limit, cAh, ajMc, dsrMc, cbrMc);
return querySuSong51(req,wsdl);
}
/**
* 将参数拼接成json字符串
* @return
*/
public static JSONObject parseStr2Json(String fyid,int page,int limit,String ah,
String ajmc,String dsr,String cbr){
JSONObject json = new JSONObject();
json.put("fyid",fyid);
json.put("page", page);
json.put("limit", limit);
if(StringUtils.isNotEmpty(ah)){
json.put("ah",ah);
}else{
json.put("ah","");
}
if(StringUtils.isNotEmpty(ajmc)){
json.put("ajmc",ah);
}else{
json.put("ajmc","");
}
if(StringUtils.isNotEmpty(dsr)){
json.put("dsr",ah);
}else{
json.put("dsr","");
}
if(StringUtils.isNotEmpty(cbr)){
json.put("cbr",cbr);
}else{
json.put("cbr","");
}
return json;
}
/**
* 将json转换成list
* @param str
* @return
*/
@SuppressWarnings("unchecked")
public static RecordingResult parseJson2List(String str){
JSONObject obj = JSONObject.fromObject(str);
RecordingResult rr = new RecordingResult();
if(obj.getBoolean("success")){
rr.setSuccess(true);
rr.setTotal(obj.getInt("total"));
JSONArray ajList = obj.getJSONArray("ajList");
List ab = new ArrayList();
for(int i=0;i
个人日记,有不对的地方请批评指正。