ksoap2自定义序列化响应

时间:2014-09-18 17:23:21

标签: android soap ksoap2 android-ksoap2

我在将响应转换为自定义类时出现问题: 以下是调用请求的代码:

SoapObject request = new SoapObject(RequestData.NAMESPACE, METHOD_LOGIN);
request.addProperty(PROPERTY_USERNAME, RequestData.USERNAME);
request.addProperty(PROPERTY_API_KEY, RequestData.API_KEY);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.enc = SoapSerializationEnvelope.ENC;
envelope.xsd = SoapSerializationEnvelope.XSD;
envelope.setOutputSoapObject(request);

HttpTransportSE transport = new HttpTransportSE(RequestData.URL);
transport.debug = true;
transport.call("", envelope);
LoginResponse response = (LoginResponse)envelope.bodyIn;

这是序列化的响应类:

public class LoginResponse implements KvmSerializable {
String sessionId;

public LoginResponse(String sessionId) {
    this.sessionId = sessionId;
}

public LoginResponse() {
}

@Override
public Object getProperty(int i) {
    return sessionId;

}

@Override
public int getPropertyCount() {
    return 1;
}

@Override
public void setProperty(int i, Object o) {
    sessionId = o.toString();

}

@Override
public void getPropertyInfo(int i, Hashtable hashtable, PropertyInfo propertyInfo) {
    propertyInfo.type = PropertyInfo.STRING_CLASS;
    propertyInfo.name = "loginReturn";

}
}

我得到的错误说:SoapObject无法转换为com.myapp ... LoginResponse。它出现在这一行:

    LoginResponse response = (LoginResponse)envelope.bodyIn;

如果我写

    SoapObject response = (SoapObject)envelope.getResponse;

而不是前一行,我没有得到错误,但我想用自定义序列化类来做。 另外,如何处理失败的响应? 感谢

0 个答案:

没有答案