dgustavocj / ksoap2-android

Automatically exported from code.google.com/p/ksoap2-android
0 stars 0 forks source link

Wrong type added for custom arrays #121

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I must send an array of custom objects to a .NET 4.0 WebService and the less 
verbose SOAP envelope I succeeded to get is the following:

<v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance" 
xmlns:d="http://www.w3.org/1999/XMLSchema" 
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
   <v:Header/>
   <v:Body>
      <SetDeliveries xmlns="http://tempuri.org/">
         <n0:deliveries i:type="c:Array" xmlns:n0="http://tempuri.org/">
            <n1:InputDeliveryInfo xmlns:n1="http://schemas.datacontract.org/2004/07/onPostServer">
               <n1:Code>AD00001</n1:Code>
               <n1:DeliveryDate>2012-05-23T11:29:17.904Z</n1:DeliveryDate>
               <n1:Latitude>0.0</n1:Latitude>
               <n1:Longitude>0.0</n1:Longitude>
               <n1:Recipient>serf</n1:Recipient>
               <n1:Status>0</n1:Status>
            </n1:InputDeliveryInfo>
            <n2:InputDeliveryInfo xmlns:n2="http://schemas.datacontract.org/2004/07/onPostServer">
               <n2:Code>AD00002</n2:Code>
               <n2:DeliveryDate>2012-05-23T07:12:48.678Z</n2:DeliveryDate>
               <n2:Latitude>0.0</n2:Latitude>
               <n2:Longitude>0.0</n2:Longitude>
               <n2:Recipient>giivanni</n2:Recipient>
               <n2:Status>0</n2:Status>
            </n7:InputDeliveryInfo>
         </n0:deliveries>
      </SetDeliveries>
   </v:Body>
</v:Envelope>

The namespace declaration is added to every item of the array (useless and too 
verbose but it works). The only way I have to make the server accept the data 
is to use VER10 otherwise I get a parsing error from the server because KSOAP2 
does not remove the attribute i:type="c:Array" in <deliveries>. The java code 
that produces the SOAP envelope above is the following:

SoapObject request = new SoapObject(wsai.getNamespace(), 
WSAccessInfo.methodSendDeliveries);

HttpTransportSE androidHttpTransport = new HttpTransportSE(wsai.getURL());
androidHttpTransport.debug = true;
MarshalDate mdate = new MarshalDate();
MarshalFloat mfloat = new MarshalFloat();

PropertyInfo pInfo = new PropertyInfo();
pInfo.setName("deliveries");
pInfo.setValue(listDeliveriesWSO);
pInfo.setNamespace(wsai.getNamespace());
pInfo.setType(Object.class);
pInfo.elementType = new PropertyInfo();
pInfo.elementType.type = DeliveryInfoWSO.class;
pInfo.elementType.name = "InputDeliveryInfo";
pInfo.elementType.namespace = 
"http://schemas.datacontract.org/2004/07/onPostServer";
request.addProperty(pInfo);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope 
SoapEnvelope.VER10);/*If I set VER12 I get an exception (strange behavior). If 
I set VER11 the sttibute i:type causes the server to return an unknown type 
error (and it is right...ksoap2 is faulty)*/

mdate.register(envelope);
mfloat.register(envelope);

envelope.avoidExceptionForUnknownProperty = true;
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setAddAdornments(false);

envelope.setOutputSoapObject(request);

envelope.addMapping(wsai.getNamespace(),
wsai.getMethosReturnTypeName(WSAccessInfo.methodSendDeliveries),
                    new DeliveryInfoWSO().getClass());

androidHttpTransport.call(wsai.getAction(WSAccessInfo.methodSendDeliveries), 
envelope);

ksoap2 should produce as less verbose XML as possible instead it generates and 
adds useless and verbose attributes and namespaces. There is also another 
problem. If I specify VER12 in the code above ksoap2 throws an XML parsing 
exception. Any hint ?

Original issue reported on code.google.com by sergio.b...@gmail.com on 25 May 2012 at 7:35

GoogleCodeExporter commented 9 years ago
Try with the latest code base in master .. it should be less verbose.

In terms of the exception you will have to provide more details or ideally a 
test case.. 

Original comment by mosa...@gmail.com on 5 Jun 2012 at 8:10