我有一个将字符串作为参数的 SOAP 服务,我会从我的 andrid 代码中调用它。在我的示例代码中,我使用 AsyncTask 来执行此操作。在 doInBackground 方法中,我调用了两个服务:第一个检索一些数据(没有参数),第二个将字符串作为参数并返回 void。
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Vector<SoapObject> result = (Vector<SoapObject>) envelope
.getResponse();
request = new SoapObject(NAMESPACE, METHOD_NAME2);
PropertyInfo property=new PropertyInfo();
property.setName("lastDate");
property.setValue("2013/09/10 14:51:08");
property.setValue(java.lang.String.class);
request.addProperty(property);
envelope.setOutputSoapObject(request);
androidHttpTransport.call(SOAP_ACTION, envelope);
但是当我尝试调用第二个服务(METHOD_NAME2)时,我得到了后续错误:
09-24 18:21:49.096: E/AndroidRuntime(23906): FATAL EXCEPTION: AsyncTask #1
09-24 18:21:49.096: E/AndroidRuntime(23906): java.lang.RuntimeException: An error occured while executing doInBackground()
09-24 18:21:49.096: E/AndroidRuntime(23906): at android.os.AsyncTask$3.done(AsyncTask.java:299)
09-24 18:21:49.096: E/AndroidRuntime(23906): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
09-24 18:21:49.096: E/AndroidRuntime(23906): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
09-24 18:21:49.096: E/AndroidRuntime(23906): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
09-24 18:21:49.096: E/AndroidRuntime(23906): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-24 18:21:49.096: E/AndroidRuntime(23906): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-24 18:21:49.096: E/AndroidRuntime(23906): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-24 18:21:49.096: E/AndroidRuntime(23906): at java.lang.Thread.run(Thread.java:841)
09-24 18:21:49.096: E/AndroidRuntime(23906): Caused by: java.lang.RuntimeException: Cannot serialize: class java.lang.String
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:664)
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:649)
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:595)
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:573)
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:658)
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:555)
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:205)
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.transport.Transport.createRequestData(Transport.java:134)
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:144)
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
09-24 18:21:49.096: E/AndroidRuntime(23906): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
09-24 18:21:49.096: E/AndroidRuntime(23906): at com.example.soapclient.DownloadDataTask.doInBackground(DownloadDataTask.java:60)
09-24 18:21:49.096: E/AndroidRuntime(23906): at com.example.soapclient.DownloadDataTask.doInBackground(DownloadDataTask.java:1)
09-24 18:21:49.096: E/AndroidRuntime(23906): at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-24 18:21:49.096: E/AndroidRuntime(23906): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
09-24 18:21:49.096: E/AndroidRuntime(23906): ... 4 more
怎么了?