1 public class WebServiceUtil {
2 private SoapObject detail;
3
4 /**
5 *
6 * @param namespace 命名空间
7 * @param methodname 调用方法
8 * @param URL 请求URL
9 * @param map 用来存放调用方法的参数
10 * @return 返回SoapObject
11 */
12 public static SoapObject getResult(String namespace, String methodname,
13 String URL, Map map) {
14 //实例化SoapObject对象
15 SoapObject so = new SoapObject(namespace, methodname);
16 //如果有参数,设置调用方法参数
17 Set keySet = map.keySet();// 返回键的集合
18 Iterator it = keySet.iterator();
19 while (it.hasNext()) // 第一种迭代方式取键值
20 {
21 Object key = it.next();
22 so.addProperty(key.toString(),map.get(key));
23 }
24
25 //获得序列化的Envelope
26 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
27 SoapEnvelope.VER11);
28 envelope.bodyOut = so;
29 envelope.dotNet = true;
30 envelope.setOutputSoapObject(so);
31
32 //Android传输对象
33 HttpTransportSE ht = new HttpTransportSE(URL);
34 ht.debug = true;
35
36 try {
37 //调用WebService(其中参数为1:命名空间+方法名称,2:Envelope对象)
38 ht.call(namespace + methodname, envelope);
39 //返回SoapObject
40 return (SoapObject) envelope.getResponse();
41 } catch (IOException e) {
42 // TODO Auto-generated catch block
43 e.printStackTrace();
44 } catch (XmlPullParserException e) {
45 // TODO Auto-generated catch block
46 e.printStackTrace();
47 }
48 return null;
49 }
50 }