Search code examples
androidsoapksoap2

How do I set the SoapObject value in kSoap2


I want to place a value in the root SoapObject in the soap body.

<envelope>
  <body>
    <request>34</request>
  </body>
</envelope>

Is there a way to set the value of the SoapObject I cannot change the server side it has to be in this format. Or is there away to set the output object as a Property?

I'm lost and about to build it from scratch and send it via http at this point.


Solution

  • The only way I found to do this is to write a simple class, which extends SoapPrimitive and implements KvmSerializable. It's look like this:

    class CustomProperty extends SoapPrimitive implements KvmSerializable
    {
        public CustomProperty(String namespace, String name, String value)
        {
            super(namespace, name, value);
        }
    
        @Override
        public Object getProperty(int index)
        {
            return this.toString();
        }
    
        @Override
        public int getPropertyCount()
        {
            return 1;
        }
    
        @Override
        public void setProperty(int index, Object value)
        {
    
        }
    
        @Override
        public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info)
        {
            info.setValue(toString());
            info.setName(getName());
            info.setNamespace(getNamespace());
        }
    }
    

    Using: envelope.setOutputSoapObject(new CustomProperty(null, "request", "34"));