创建一个实现的类KvmSerializeable
:
public class Import implements KvmSerializable {
String test;
public Import() {}
public Import (String test) {
this.test = test;
}
public Object getProperty(int arg0) {
switch (arg0) {
case 0:
return test;
default:
return test;
}
}
public int getPropertyCount() {
return 1;
}
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch (arg0) {
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "test";
break;
default:
break;
}
}
public void setProperty(int arg0, Object arg1) {
switch (arg0) {
case 0:
test = (String) arg1;
break;
}
}
}
只需更改变量,使其适合您的需要。进而:
SoapObject soapObject = new SoapObject(NAMESPACE_NIST_IMPORT,
METHOD_NAME_NIST_IMPORT);
Import import= new Import("Hello, World!");
PropertyInfo pi = new PropertyInfo();
pi.setName("req");
pi.setValue(import);
pi.setType(import.getClass());
soapObject.addProperty(pi);
SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapSerializationEnvelope.setOutputSoapObject(soapObject);
soapSerializationEnvelope.addMapping(NAMESPACE, "Import", new Import().getClass());
要解析响应:
SoapObject response = (SoapObject)soapSerializationEnvelope.getResponse();
Import.test= response.getProperty(0).toString();