2

I've send several simple objects with kSOAP 2 before, but now I have to send an object that contains an array of integers...

So I looked at this other SO post: Serialize an array of ints to send using kSOAP2 But I'm getting the same problem as the author of that post - I get an error back saying:

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:recipientIds. The InnerException message was 'Error in line 1 position 650. Element 'http://tempuri.org/:recipientIds' contains data from a type that maps to the name 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:recipientIds'. The deserializer has no knowledge of any type that maps to this name.

My class:

public class AddMessageConnection {
    private static final String SOAP_ACTION = "http://tempuri.org/IKindergarden/AddMessageAboutKid";
    private static final String METHOD_NAME = "AddMessageAboutKid";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String NESTED_NAMESPACE = "http://schemas.microsoft.com/2003/10/Serialization/Arrays";
    private String URL;
    public String msg;
    public String kidID;
    public ArrayList<String> listOfEmployees = new ArrayList<String>();

    void connection()
    {
        Singleton service = Singleton.getInstance();
        service.getURL();
        String firstURL = service.getURL();
        URL = firstURL + "Kindergarden.svc";

        //Get parentID, parentToken
        String parentIDSingleton = service.getParentID();
        String parentTokenSingleton = service.getParentToken();

        //Initialize soap request
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        //Add parameters
        request.addProperty("authorId", service.getParentID());
        request.addProperty("relatesToKidId", kidID);

        SoapObject recipients = new SoapObject(NESTED_NAMESPACE, "recipientIds");

        //Add the recipients
        List<Integer> recp = new ArrayList<Integer>();
        //Iterate through recipients and add them
        for(int i = 0; i < listOfEmployees.size(); i++)
        {
            int converted = Integer.parseInt(listOfEmployees.get(i));
            recp.add(converted);
        }

        for(Integer i:recp)
        {
            recipients.addProperty("int", i);   
        }

        request.addSoapObject(recipients);

        request.addProperty("sMessage", msg);

        //Declare the version of the SOAP request
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        //Debugging
        envelope.avoidExceptionForUnknownProperty=true;

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

        //Prepare request
        envelope.setOutputSoapObject(request);

        //Needed to make the internet call
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        //Allow for debugging - needed to output the request
        androidHttpTransport.debug = true;

        try 
        {
            //this is the actual part that will call the web service
            androidHttpTransport.call(SOAP_ACTION, envelope);

            System.out.println("Request: " + androidHttpTransport.requestDump.toString());
            System.out.println("Response: " + androidHttpTransport.responseDump.toString());

        } catch(org.xmlpull.v1.XmlPullParserException ex2)
        {               
            System.out.println(androidHttpTransport.requestDump.toString());

        }  catch (Exception e)
        {
            e.printStackTrace();
            System.out.println(androidHttpTransport.requestDump.toString());
        }
    }
}

So I'm trying to fix this with the assumption that the error lies with the namespace... Has anyone got any clues as to what I should change?

SoapUI says that the service expects:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:AddMessageAboutKid>
         <!--Optional:-->
         <tem:authorId>?</tem:authorId>
         <!--Optional:-->
         <tem:relatesToKidId>?</tem:relatesToKidId>
         <!--Optional:-->
         <tem:recipientIds>
            <!--Zero or more repetitions:-->
            <arr:int>?</arr:int>
         </tem:recipientIds>
         <!--Optional:-->
         <tem:sMessage>?</tem:sMessage>
      </tem:AddMessageAboutKid>
   </soapenv:Body>
</soapenv:Envelope>

I've done the request in iOS, where the xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:day="http://schemas.datacontract.org/2004/07/DayCare.DB.DTO">
<s:Header>
    <parentId xmlns="ns">2104541932</parentId>
    <parentToken xmlns="ns">00430050004A00430046004C0052</parentToken>
    <authType xmlns="ns">Parent</authType>
    <id xmlns="ns">1</id>
</s:Header>
<s:Body>
<AddMessageAboutKid xmlns="http://tempuri.org/">
    <authorId>2104541932</authorId>
    <relatesToKidId>2104535510</relatesToKidId>
    <recipientIds xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        <d4p1:int>2104535836</d4p1:int>
        <d4p1:int>2104535839</d4p1:int>
    </recipientIds>
    <sMessage>Test</sMessage>
</AddMessageAboutKid>
</s:Body>
</s:Envelope>

whereas my xml from kSOAP2 ends up as:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header>
    <n0:parentId xmlns:n0="ns">2104536774</n0:parentId>
    <n1:parentToken xmlns:n1="ns">0003</n1:parentToken>
    <n2:authType xmlns:n2="ns">Parent</n2:authType>
    <n3:id xmlns:n3="ns">1</n3:id>
</v:Header>
<v:Body>
<AddMessageAboutKid xmlns="http://tempuri.org/">
    <authorId>2104536774</authorId>
    <relatesToKidId>2104535421</relatesToKidId>
    <recipientIds i:type="n4:recipientIds" xmlns:n4="http://tempuri.org/">
        <int>2104535482</int>
        <int>2104535485</int>
    </recipientIds>
    <sMessage>Test</sMessage>
</AddMessageAboutKid>
</v:Body>
</v:Envelope>

So my guess is that the problem lies with the recipientIds namespace... where in iOS I set , I currently only have in Android, but I'm not sure how to properly set it up with my SoapObjects...

Community
  • 1
  • 1
user1368800
  • 131
  • 4
  • 14
  • What version of ksaop2-android are you using? The issue you linked to is fixed already.. – Manfred Moser May 31 '12 at 16:12
  • I'm 90% sure that my issue is with my namespace for the int's I'm adding... I know from when I did this call in iOS, that I use the common http://tempuri.org/ for all parameters, but that http://schemas.microsoft.com/2003/10/Serialization/Arrays\ should be used somehow with the int's, but apparently the way I'm doing it here is wrong – user1368800 May 31 '12 at 16:19
  • It might ahve to do with the fact that you are declaring to add "int" but in fact you are adding Integers.. – Manfred Moser May 31 '12 at 18:05
  • Thanks for the suggestion, Manfred, but that wasn't it... I've changed it though, from so I from arraylist of Integers to an array of int's though... But the issue is still the same, it's a matter of the server not being able to deserialize the recipientIds parameters, because it doesn't map correctly... – user1368800 May 31 '12 at 18:44
  • So is it a server side issue or an issue with the generated xml? – Manfred Moser May 31 '12 at 19:11
  • Manfred Moser, I've updated the original question with some new info regarding the xml, as that's where the problem lies... – user1368800 May 31 '12 at 20:35

1 Answers1

0

Try adding the recipients like this

request.addProperty("Arrays", recipients);

or even

request.addProperty("http://schemas.microsoft.com/2003/10/Serialization/Arrays", recipients);
Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • Hm... Can't do that... .addSoapObject only takes one parameter (a SoapObject)... request.addSoapObject(soapObject) – user1368800 May 31 '12 at 20:50
  • Thanks, but doesn't work :( Gives the error: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:relatesToKidId. The InnerException message was 'There was an error deserializing the object of type System.Int32. Name cannot begin with the '/' character, hexadecimal value 0x2F. Line 1, position 543.'- Req. is `AddMessageAboutKid{authorId=2104536774; relatesToKidId=2104535421; http://schemas.microsoft.com/2003/10/Serialization/Arrays=recipientIds{int=2104536497; int=2104535482; }; sMessage=test; }` – user1368800 May 31 '12 at 22:54
  • what about just using Arrays? but then I have a feeling that will be wrong too since it will affect the name .. not the type.. I would have to play with this, but dont have the time. Looking at the SoapObject code it should definitely be possible. – Manfred Moser May 31 '12 at 23:16
  • Yeah, same issue :( Thanks anyway though.. Been trying to get this to work for soooo long now, but doesn't seem likely at the moment – user1368800 May 31 '12 at 23:32
  • You will have to debug into the ksoap2 codebase and see what is going on.. then you will find out. I just don't have the time to do it for you. Have you looked at all the unit test to see if something similar is there? – Manfred Moser Jun 01 '12 at 05:37