Search code examples
javaandroidweb-servicesksoap2

Empty object uploaded using ksoap2 in android


Each time I upload a new Object it commits to database an empty object and ignores all parameters I set to it.

Here is android side:

public void createGroupServ(String groupName)
{
    request = new SoapObject(NAMESPACE, "createGroup");

    Group gr = new Group();
    gr.setGroupId(1L);
    gr.setGroupName("xxxx");
    gr.setUsers(null);

    PropertyInfo object = new PropertyInfo();
    object.setName("arg0");
    object.setValue(gr);
    object.setType(gr.getClass());
    request.addProperty(object);

    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = false;
    envelope.setOutputSoapObject(request);
    envelope.addMapping(NAMESPACE, "group", new Group().getClass());

    androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;

}

and domain class Group:

public class Group implements KvmSerializable {
    private long groupId;
    private String groupName;
    private List<User> users = null;

...setter and getters ...
}

My WSDL xml:

<xs:complexType name="group">
<xs:sequence>
<xs:element name="groupId" type="xs:long"/>
<xs:element name="groupName" type="xs:string" minOccurs="0"/>
<xs:element name="users" type="tns:user" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="createGroup">
<xs:sequence>
<xs:element name="arg0" type="tns:group" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

Any advice on why it doesn't upload the whole object with group name parameter ?


Solution

  • OK, i have fixed this. I didn't implement methods of KvmSerializable interface -

    public Object getProperty
    public int getPropertyCount
    public void getPropertyInfo
    public void setProperty
    

    which can be found here: http://seesharpgears.blogspot.co.uk/2010/10/ksoap-android-web-service-tutorial-with.html

    Besides, I made my soap object request as a separate class, because it didn't work in MainActivity for me.