- 在服务器上有一Webservice  地址:http://117.40.139.43:5000/BitcareMobileService/MobileRegister.asmx?op=GetHosInfoAll
- 然后我想获取里面的数据。
用这个方法连接服务器上的Webservice
public String[] GetHosInfoAll(String SOAP_ACTION,String methodName,String MethodDataResult,String HospitalID)throws Exception{
String[][] data = {{"HospitalID",HospitalID}};
return GetArray(SOAP_ACTION,methodName,MethodDataResult,data);
}
然后再用这个方法输出获取到的字符串
public void testGetHosInfoAll() throws Exception{
GetWebService getWebService = new GetWebService();
String[] value = getWebService.GetHosInfoAll("http://tempuri.org/GetHosInfoAll", "GetHosInfoAll", "GetHosInfoAllResult", "07910001");
Log.i(TAG,"testGetHosInfoAll:"+new Integer(value.length).toString());
Log.i(TAG,"testGetHosInfoAll:"+value[0]+value[1]+value[2]);
}
- 但是,却报了java.lang.ClassCastException: org.ksoap2.SoapFault这个错。- 提示这里:SoapObject result = (SoapObject) envelope.bodyIn;有问题。
- 希望各位专家能为小弟指点一二……谢谢!

解决方案 »

  1.   

    SoapObject result = (SoapObject) envelope.bodyIn;有问题。把(SoapObjecdt)改成Object就好了
      

  2.   

    - 这类型转换就过不去了……怎么能把Object类型强制转换成SoapObject类型呢???
      

  3.   

    http://stackoverflow.com/questions/4439934/accessing-the-webservice-in-android-using-ksoap2
      

  4.   

    首先你的结贴率有点低!其次,核心代码没贴上来, 你是不是用的ksoap2包连接webService ?一行与soap相关代码都没看到
      

  5.   

    - 额,结贴率低,这页面显示的是33。33%
    - 我其他页面显示的都是80%,这貌似不能说明是我的原因吧。
    - 用的是Android自带的ksoap2包连接webService……
      

  6.   

    String namespace = null;
    //服务器发布的url
    String url = null;
    public GetWebService() {
    this.namespace =  "http://tempuri.org/";
    this.url = "http://117.40.139.43:5000/BitcareMobileService/MobileRegister.asmx";
    }

    //获得数组的情况
    public String[] GetArray(String SOAP_ACTION,String methodName,String MethodDataResult,String[][] data) throws Exception{
    String value=null;
    String[] resultstring=null;
    // 指定WebService的命名空间和函数名
    SoapObject soapObject = new SoapObject(namespace, methodName);
    // 设置调用方法参数的值
    if(data != null) {
    for(int i = 0;i<data.length;i++)
    soapObject.addProperty(data[i][0], data[i][1]);
    }
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet=true; 
    envelope.bodyOut=soapObject;
    envelope.setOutputSoapObject(soapObject);
    // 创建HttpTransportSE对象,通过HttpTransportSE类的构造方法可以指定WebService的url
    AndroidHttpTransport transport = new AndroidHttpTransport(url);
    transport.debug = true;
    //使用call方法调用WebService方法
    try {
    transport.call(SOAP_ACTION, envelope);//transport.call(null, envelope);
    SoapObject result = (SoapObject) envelope.bodyIn;
    SoapObject detailfirst = (SoapObject) result.getProperty(MethodDataResult);
    if(envelope.getResponse()!=null){
    int numfirst = detailfirst.getPropertyCount();
    resultstring = new String[numfirst];
    for(int i =0;i<numfirst;i++){
    resultstring[i] = detailfirst.getProperty(i).toString(); 
    }
    }else{
    value ="获取到空的XML字符串";
    }
    } catch (IOException e) {
    value ="IOException and XML error";
    e.printStackTrace();
    } catch (XmlPullParserException e) {
    value ="XmlPullParserException未获取到XML字符串";
    e.printStackTrace();
    }
    return resultstring;
    }- 然后是上面写的两个调用的方法……
      

  7.   

    Android 自带 ksoap2 了???
      

  8.   


    - ksoap2 for android ! 谢谢指正!
    - KSOAP2 Android项目提供了一个为Android平台的轻量级和高效的SOAP库!
      

  9.   

    soapObject.addProperty(data[i][0], data[i][1]);
    第一个参数名称与WebService中定义不一致时可能会报java.lang.ClassCastException: org.ksoap2.SoapFault错误。
      

  10.   

    加上下面一句 应该就OK了
    envelope.dotNet = true;
      

  11.   

    我也有同样的错误,后面我把 soapObject = (SoapObject) envelope.bodyIn换成soapObject = (SoapObject) envelope.getResponse();就可以了
      

  12.   

    你打印一下envelope.bodyIn内容,很可能是服务器错误
    我曾经遇到这样的错误是由服务器以下原因造成的,希望对你有帮助
    1、 INFO/System.out(2185): SoapFault - faultcode: 'soapenv:Server.userException' faultstring: 'java.lang.NullPointerException' faultactor: 'null' detail: org.kxml2.kdom.Node@40662450
    是服务器数据库未开启
    2、null
    服务器防火墙未关闭
      

  13.   

    3、null
    还有可能是服务器IP更改
      

  14.   


    请问服务器IP更改是什么意思。我是在自己计算机上写的WEBSERVICE 
    之前调用bodyIn的时候显示java.lang.ClassCastException: org.ksoap2.SoapFault 这个错误
    改成response()方法之后  就变成了 W/System.err(824): SoapFault - faultcode: 'soapenv:Server' faultstring: '3' faultactor: 'null' detail: org.kxml2.kdom.Node@46058dd8