处理org.ksoap2.serialization.SoapSerializationEnvelope响应会引发错误

时间:2015-11-26 09:16:52

标签: android android-ksoap2

我编写了一个SoapSerializationEnvelope来为android中的数据请求asmx Web服务。我正在捕获Soap请求的响应,如下所示

  SoapSerializationEnvelope envelope=getSoapSeraializationEnvolope(request);
/*Here I have written code for Creating Soap request and Sending Soap request which has no problem at all*/
         SoapPrimitive resultsString;
            //Processing the response
            try
            {
            resultsString = (SoapPrimitive)envelope.getResponse();
            return resultsString.toString();
            }

getSoapSerializationEnvolope的功能如下

//Creating an Envelope here...
    private SoapSerializationEnvelope getSoapSeraializationEnvolope(SoapObject request) {
        // TODO Auto-generated method stub
        SoapSerializationEnvelope envolope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envolope.dotNet=true;
        envolope.implicitTypes=true;
        envolope.setAddAdornments(false);
        envolope.setOutputSoapObject(request);
        MarshalDouble marshaldDouble = new MarshalDouble();
        marshaldDouble.register(envolope);
        return envolope;
    }

但问题在于webService返回一个字符串数据(例如 - " Message Sent")响应没有问题,但是当我的webservice返回一个空字符串数据时(即返回"")它给出了一个例外

java.lang.ClassCastException: org.ksoap2.serialization.SoapObject cannot be cast to org.ksoap2.serialization.SoapPrimitive 

我也试过转换成SoapObject而不是Soap Primitive但是在这里我得到错误它是反向的(即当从web服务返回的字符串中有一些数据时,它会抛出错误。)

为什么会这样?

先谢谢!!

0 个答案:

没有答案