SoapObject request = new SoapObject(NAMESPACE, "api_vps_get_service");
// Property which holds input parameters
PropertyInfo unamePI = new PropertyInfo();
// Set token
unamePI.setName("token");
// Set Value
unamePI.setValue(token);
// Set dataType
unamePI.setType(String.class);
// Add the property to request object
request.addProperty(unamePI);
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// Invoke web service
androidHttpTransport.call(SOAP_ACTION+"api_vps_get_service", envelope);
// Get the response
SoapObject response=(SoapObject)envelope.bodyIn;
String reponses = response.toString();
Log.i("reponse", String.valueOf(reponses));
} catch (Exception e) {
//Assign Error Status true in static variable 'errored'
Home.errored = true;
e.printStackTrace();
}
我收到此错误java.lang.ClassCastException:org.ksoap2.SoapFault无法强制转换为org.ksoap2.serialization.SoapObject我试过SoapPrimitive response =(SoapPrimitive)envelope.getResponse();还有Object response =(Object)envelope.getResponse();但没有成功的人请告诉我为什么我收到错误?
答案 0 :(得分:1)
服务器返回错误。所以没有SoapObject和SoapPrimitive。你必须首先检查SoapFoult:
if (envelope.bodyIn instanceof SoapFault)
{
final SoapFault sf = (SoapFault) envelope.bodyIn;
... // Stuff
}
这里描述: https://code.google.com/p/ksoap2-android/issues/detail?id=177