如何解决java.lang.runtimeexception无法序列化ksoap2

时间:2014-08-06 07:16:25

标签: java android soap

在我的项目中,我使用kso​​ap2-android-assembly-2.4-jar-with-dependencies.jar进行Web服务。

我能够访问服务并传递简单参数并获取对象并进行迭代。

但问题是我无法发送复杂的对象。任何人都可以知道如何使用日期和双精度值传递复杂对象。

Employee对象具有字符串名称,int号,双薪和Date dateOfBirth。

And the employee object implements KvmSerializable
name="Mike"
number=2;
salary=20000
dateOfBirth = new Date();

,代码是

SOAP_ACTION = "http://xysed/GetHRA";
METHOD_NAME = "GetHRA";

TextView authenticate = new TextView(this);

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

PropertyInfo pi = new PropertyInfo();
pi.setName("employee");
Employee e = new Employee();
e.setNumber(4);
e.setName("Ananth");
e.setSalary(20000);
e.setDob(new Date());
pi.setValue(e);
pi.setType(Employee.EMPLOYEE_CLASS);
request.addProperty(pi);
request.addProperty("employee", e);


SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
Marshal dateMarshal = new MarshalDate();
dateMarshal.register(envelope);
//envelope.addMapping(Employee.NAMESPACE, "Employee", new Employee().getClass());
try {
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);

//String fullName = (String)envelope.getResponse();
Log.v("Full String :", envelope.getResponse().toString());
Log.v("body in :", envelope.bodyIn.toString());
Log.v("body out :", envelope.bodyOut.toString());

authenticate.setText(envelope.getResponse().toStri ng());
this.setContentView(authenticate);

} catch (IOException ioe) {
ioe.printStackTrace();
} catch (XmlPullParserException xpe) {
xpe.printStackTrace();
}

我将此员工对象作为请求传递,例如

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.oak.soap.test/com.oak.soap.test.WebserviceDisplay}: java.lang.RuntimeException: Cannot serialize: 20000.0

here 20000.0 is a salary ( double value)

ERROR/AndroidRuntime(287): Caused by: java.lang.RuntimeException: Cannot serialize: 20000.0

任何人都可以提供如何将复杂对象作为请求传递给Web服务的示例

由于

0 个答案:

没有答案