How to map SoapObject response to MyObject using KvmSerializable?
I read the wiki on ksoap2-android. But still I can’t do it.
I added the card to the envelope:
envelope.addMapping(NAMESPACE, "return", new GoodsObject().getClass());
But I get an exception:
java.lang.ClassCastException: org.ksoap2.serialization.SoapObject
on the line
GoodsObject resultsRequestSOAP = (GoodsObject) envelope.bodyIn
The code is below. I spent a lot of time on this problem, but I have no ideas yet (
Java GoodsObject Class :
package com.deaddy64.droid;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class GoodsObject implements KvmSerializable {
public String ref;
public String DeletionMark;
public String Code;
public String Description;
private static final long serialVersionUID = -4872313975732374054L;
public void setref(String strref) {
this.ref = strref;
}
public String getref() {
return this.ref;
}
public void setDeletionMark(String strDeletionMark) {
this.DeletionMark = strDeletionMark;
}
public String getDeletionMark() {
return this.DeletionMark;
}
public void setCode(String strCode) {
this.Code = strCode;
}
public String getCode() {
return this.Code;
}
public void setDescription(String strDescription) {
this.Description = strDescription;
}
public String getDescription() {
return this.Description;
}
public Object getProperty(int index) {
switch (index) {
case 0:
return ref;
case 1:
return DeletionMark;
case 2:
return Code;
case 3:
return Description;
}
return null;
}
public int getPropertyCount() {
return 4;
}
public void setProperty(int index, Object value) {
switch(index) {
case 0:
this.ref = value.toString();
break;
case 1:
this.DeletionMark = value.toString();
break;
case 2:
this.Code = value.toString();
break;
case 3:
this.Description = value.toString();
break;
default:
break;
}
}
public void getPropertyInfo(int index, Hashtable properties,
PropertyInfo info) {
switch (index) {
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Ref";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "DeletionMark";
break;
case 2:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Code";
break;
case 3:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Description";
break;
}
}
}
This is a ResponseDump :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body> <m:getReferenceResponse xmlns:m="com.deaddy64">
<m:return xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Ref xmlns="http://v8.1c.ru/8.1/data/enterprise/current-config">7f4fb970-6a62-11e1-9bd0-001fd027b6bb</Ref>
<DeletionMark xmlns="http://v8.1c.ru/8.1/data/enterprise/current-config">false</DeletionMark>
<Code xmlns="http://v8.1c.ru/8.1/data/enterprise/current-config">000000003</Code>
<Description xmlns="http://v8.1c.ru/8.1/data/enterprise/current-config">123</Description>
</m:return>
</m:getReferenceResponse></soap:Body>
</soap:Envelope>
The envelope.bodyIn debugger has:
(org.ksoap2.serialization.SoapObject) getReferenceResponse{return=anyType{Ref=7f4fb970-6a62-11e1-9bd0-001fd027b6bb; DeletionMark=false; Code=000000003; Description=123; }; }
Primary activity:
package com.deaddy64.droid;
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract.Contacts;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Droid1Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String NAMESPACE = "com.deaddy64";
String URL = "http://10.0.2.2/InfoBase/ws/ws1.1cws";
String SOAP_ACTION = "com.deaddy64#testService:getReference";
String METHOD_NAME = "getReference";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.addMapping("http://v8.1c.ru/8.1/data/enterprise/current-config", "CatalogObject.", new GoodsObject().getClass());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
androidHttpTransport.debug = true;
Log.v("dd64", "xml");
GoodsObject resultsRequestSOAP;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
resultsRequestSOAP = (GoodsObject) envelope.getResponse();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
Log.v("dd64",androidHttpTransport.requestDump);
Log.v("dd64", androidHttpTransport.responseDump);
}
});
}
}
source
share