/** WEBSERVICE访问地址 */
private static final String URL = "http ....";
/** WEBSERVICE 命名空间 */
private static final String URL_SPACE = "http ....";
/** 方式一:webservice传过来的一个json数据格式*/
/**
*
* @param mehtodName
* 调用的方法名
* @param map
* 需要传入的参数
* @return
*/
@SuppressWarnings("rawtypes")
public String query(String mehtodName, Map<String, String> map) {
System.out.println("webservice query()被调用!");
String result = "";
try {
SoapObject soapObject = new SoapObject(URL_SPACE, mehtodName);
Set set = map.entrySet();
Iterator it = set.iterator();
while (it.hasNext()) {
@SuppressWarnings("unchecked")
Map.Entry<String, String> entry = (Entry<String, String>) it
.next();
soapObject.addProperty(entry.getKey(), entry.getValue());
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER10);
envelope.bodyOut = soapObject;
envelope.dotNet = false;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE transportSE = new HttpTransportSE(URL);
transportSE.call(URL_SPACE + mehtodName, envelope);
if(envelope.getResponse()!=null){
SoapObject object = (SoapObject) envelope.bodyIn;
result = object.getProperty(0).toString();
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("webservice query()被调用!异常");
result = "false";
}
System.out.println("result********"+result);
return result;
}
/** 方式二:webservice传过来的一个list或者是单一的数据*/
/**
*
* @param mehtodName
* 调用的方法名
* @param tabname
* 需要传入的参数
* @return
*/
public List<Object> query(String mehtodName, String tabname) {
List<Object> result = new ArrayList<Object>();
try {
SoapObject soapObject = new SoapObject(URL_SPACE, mehtodName);
soapObject.addProperty("val", tabname);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.bodyOut = soapObject;
envelope.dotNet = false;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE transportSE = new HttpTransportSE(URL);
transportSE.call(URL_SPACE + mehtodName, envelope);
SoapObject object = (SoapObject) envelope.getResponse();
//如果获取的是个集合,就对它进行下面的操作
if(object.getName().equals("anyType")){
//遍历Web Service获得的集合
for(int i=0;i<object.getPropertyCount();i++){
Object m = object.getProperty(i);
result.add(m);
}
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return result;
}
177

被折叠的 条评论
为什么被折叠?



