毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> 移动平台 >> 正文

ksoap2_WebService问题

更新时间:2013-3-27:  来源:毕业论文

ksoap2_WebService问题
小弟初学Android,写了个webservice程序。Server是asp.net写的,客户端是android。
先上错误代码

代码如下
ActivityWebService.java

Java code?package com.ll.android.glif_v3;   import java.io.IOException; import java.util.ArrayList; import java.util.List;   import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import org.xmlpull.v1.XmlPullParserException;       public class ActivityWebService {         // 毕业论文 定义Web Service的命名空间         static final String SERVICE_NS = "http://xxx.xxx.xxx:812/";         // 定义Web Service提供服务的URL         static final String SERVICE_URL = "http://xxx.xxx.xxx:812/Service.asmx";         // 调用远程Web Service获取省份列表         public static List<String> getDataList(String con)         {             // 调用的方法             String methodName = "getEscapeDataList";             // 创建HttpTransportSE传输对象             HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);             ht.debug = true;             // 使用SOAP1.1协议创建Envelop对象             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(                 SoapEnvelope.VER11);             // 实例化SoapObject对象             SoapObject soapObject = new SoapObject(SERVICE_NS, methodName);             // 添加一个请求参数             soapObject.addProperty("theRegionCode", con);             envelope.bodyOut = soapObject;             // 设置与.Net提供的Web Service保持较好的兼容性             envelope.dotNet = true;             try            {                 // 调用Web Service                 ht.call(SERVICE_NS + methodName, envelope);                 if (envelope.getResponse() != null)                 {                     // 获取服务器响应返回的SOAP消息                     SoapObject result = (SoapObject) envelope.bodyIn;                     SoapObject detail = (SoapObject) result.getProperty(methodName                         + "Result");                     // 解析服务器响应的SOAP消息。                     return parseEscapeList(detail);                 }             }             catch (IOException e)             {                 e.printStackTrace();             }             catch (XmlPullParserException e)             {                 e.printStackTrace();             }             return null;         }                   private static List<String> parseEscapeList(SoapObject detail)         {             ArrayList<String> result = new ArrayList<String>();             for (int i = 0; i < detail.getPropertyCount(); i++)             {                 // 解析出每一条                 result.add(detail.getProperty(i).toString());             }             return result;         }               }

mainActivity.java 代码如下

Java code?package com.ll.android.glif_v3;   import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;   import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.ListView; import android.widget.SimpleAdapter;   public class ActivityMenu extends Activity {       @Override    protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_query);         String con="";         List<String> escapeList=new ArrayList<String>();         escapeList=ActivityWebService.getDataList(con);                       List<String> a=new ArrayList<String>();         List<String> b=new ArrayList<String>();         List<String> c=new ArrayList<String>();         List<String> d=new ArrayList<String>();         List<String> e=new ArrayList<String>();                       for(int i=0;i<escapeList.size();i++)         {             a.add(escapeList.get(i).split(",")[0]);             b.add(escapeList.get(i).split(",")[1]);             c.add(escapeList.get(i).split(",")[2]);             d.add(escapeList.get(i).split(",")[3]);             e.add(escapeList.get(i).split(",")[4]);                           }                       String aStr[] = vehiclesCard.toArray(new String[]{});          String bStr[] = escapeTime.toArray(new String[]{});         String cStr[] = vehiclesType.toArray(new String[]{});         String dStr[] = escapePlace.toArray(new String[]{});         String eStr[] = escapeStates.toArray(new String[]{});                   List<Map<String,Object>> listItems=new ArrayList<Map<String,Object>>();         for(int i=0;i<vehiclesCardStr.length;i++){             Map<String,Object> listItem=new HashMap<String,Object>();             listItem.put("A", vehiclesCardStr[i]);             listItem.put("B", escapeTimeStr[i]);             listItem.put("C", vehiclesTypeStr[i]);             listItem.put("D", escapePlaceStr[i]);             listItem.put("E", escapeStatesStr[i]);             listItems.add(listItem);         }                   SimpleAdapter simpleAdapter=new SimpleAdapter(this                ,listItems                 ,R.layout.activity_query                 ,new String[]{"A","B","C","D","E"}                 ,new int[]{R.id.A,R.id.B,R.id.C,R.id.D,R.id.E});             ListView list=(ListView)findViewById(R.id.myList);         list.setAdapter(simpleAdapter);     }       @Override    public boolean onCreateOptionsMenu(Menu menu) {         // Inflate the menu; this adds items to the action bar if it is present.         getMenuInflater().inflate(R.menu.activity_menu, menu);         return true;     }   }


水平实在有限,求大神帮忙,谢谢了!我要疯了- -||

envelope.dotNet = false; 把这个改为false试下

是不是manifest里的路径写错了?仔细检查一下

产生问题的原因是WebService引用的命名空间不对。希望以后遇到这个问题的注意。

Java code?1 static final String SERVICE_NS = "http://xxx.xxx.xxx:812/";


这里一定要和webservice返回的一样才行

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。