是否有可能将复杂对象的数组发送到服务器,我尝试了kvmSerializable接口,仍然无法在运行时序列化错误。 logcat中的细节和错误如下。
我试图访问的wsdl文件部分如下
<xs:complexType name="filterIPResources">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="tns:resourcePageDetails"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="resourcePageDetails">
<xs:complexContent><xs:extension base="tns:pageDetails">
<xs:sequence><xs:element maxOccurs="unbounded" minOccurs="0" name="inventoryFilterList" nillable="true" type="tns:inventoryFilter"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="inventoryFilter">
<xs:sequence><xs:element minOccurs="0" name="filterType" type="tns:filterType"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="filterValue" nillable="true" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="filterIPResourcesResponse">
<xs:sequence><xs:element minOccurs="0" name="return" type="tns:pageResult"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="pageDetails">
<xs:sequence>
<xs:element name="blockSize" type="xs:int"/>
<xs:element name="currentStartIndex" type="xs:int"/>
</xs:sequence>
</xs:complexType>
logcat中的错误如下
01-09 15:19:23.561: E/AndroidRuntime(1945): FATAL EXCEPTION: AsyncTask #2
01-09 15:19:23.561: E/AndroidRuntime(1945): java.lang.RuntimeException: An error occured while executing doInBackground()
01-09 15:19:23.561: E/AndroidRuntime(1945): at android.os.AsyncTask$3.done(AsyncTask.java:278)
01-09 15:19:23.561: E/AndroidRuntime(1945): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
01-09 15:19:23.561: E/AndroidRuntime(1945): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
01-09 15:19:23.561: E/AndroidRuntime(1945): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
01-09 15:19:23.561: E/AndroidRuntime(1945): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-09 15:19:23.561: E/AndroidRuntime(1945): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
01-09 15:19:23.561: E/AndroidRuntime(1945): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-09 15:19:23.561: E/AndroidRuntime(1945): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-09 15:19:23.561: E/AndroidRuntime(1945): at java.lang.Thread.run(Thread.java:856)
01-09 15:19:23.561: E/AndroidRuntime(1945): Caused by: java.lang.RuntimeException: Cannot serialize: [com.example.inventory.InventoryFilter@4138a178]
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:687)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:671)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:640)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:683)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:671)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:640)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:624)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:681)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:597)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:192)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.transport.Transport.createRequestData(Transport.java:101)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
01-09 15:19:23.561: E/AndroidRuntime(1945): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:90)
01-09 15:19:23.561: E/AndroidRuntime(1945): at com.example.inventory.Search$ShowDialogAsyncTask2.doInBackground(Search.java:89)
01-09 15:19:23.561: E/AndroidRuntime(1945): at com.example.inventory.Search$ShowDialogAsyncTask2.doInBackground(Search.java:1)
01-09 15:19:23.561: E/AndroidRuntime(1945): at android.os.AsyncTask$2.call(AsyncTask.java:264)
01-09 15:19:23.561: E/AndroidRuntime(1945): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-09 15:19:23.561: E/AndroidRuntime(1945): ... 5 more
用于使用Web服务的Asynctask如下
private class ShowDialogAsyncTask2 extends AsyncTask<String, Void, SoapObject> {
@Override
protected SoapObject doInBackground(String... urls) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME3);
inventoryFilters = new ArrayList<InventoryFilter>();
filter = new InventoryFilter();
rpd = new ResourcePageDetails();
Object[] deviceTypes = { DeviceType.HOST };
filter.setProperty(0, FilterType.DEVICE_TYPE);
filter.setProperty(1, deviceTypes);
inventoryFilters.add(0, filter);
rpd.setProperty(0, 1);
rpd.setProperty(1, 15);
rpd.setProperty(2, inventoryFilters);
request.addProperty("arg0",rpd);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.addMapping(NAMESPACE, "resourcePageDetails", ResourcePageDetails.class);
envelope.addMapping(NAMESPACE, "InventoryFilter", InventoryFilter.class);
envelope.addMapping(NAMESPACE, "Devicetype.HOST", DeviceType.class);
envelope.addMapping(NAMESPACE, "FilterType.DEVICE_TYPE", FilterType.class);
envelope.setOutputSoapObject(request);
androidTransport = new HttpTransportSE(URL1);
androidTransport.debug = true;
try {
androidTransport.call(SOAP_ACTION3, envelope);
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
Log.d("xml", e.toString());
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("MyAPP", "----------------- " + androidTransport.requestDump + "\n\n"
+ androidTransport.responseDump);
return soap;
}
@Override
protected void onPostExecute(SoapObject resultt) {
super.onPostExecute(resultt);
}
}
过去3天我试图解决这个问题......但是根本没有成功。如果有人知道如何解决这个问题,请帮助我..
答案 0 :(得分:0)
你有2个对象: filter = new InventoryFilter(); 和 rpd = new ResourcePageDetails(); ,那么你需要从ksoap实现KvmSerializable接口。您可以使用这些文章: java.lang.RuntimeException: Cannot serialize: MyClass 和 http://www.sgoliver.net/blog/?p=2594