When to use Soapobject and SoapPrimitive
SoapObject is used when we need to get the Response for a Class type, like Customer, Product, etc. (From the SoapObject you need to iterate over the values inside the SoapResponse.) SoapPrimitive is used for Primitive datatypes like Integer, Boolean.
For example, in the following code I am expecting a Boolean value from SoapResponse:
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
Boolean status = Boolean.valueOf(response.toString());
And in the following code, I need to get the Response as an Object:
SoapObject response = (SoapObject) envelope.getResponse();
Log.d("Response", response.toString());
int count = response.getPropertyCount();
for (int i = 0; i < count; i++) {
userObj = new User(response.getProperty(1).toString(),
Double.parseDouble(response.getProperty(2).toString()));
}
Shachi
Inquisitive & Quick Learner Ideology - Strive to give an extra 10% to what you do.
Updated on June 25, 2022Comments
-
Shachi almost 2 years
I have been working with
ksoap2
lately.I am still confused whether what is the EXACT difference between
SoapObject
andSoapPrimitive
.And when to use them.
I guess its something related to string and arrays. Is it true?
I found some links but got confused.
Can anyone tell me the difference and when to use which one in the simplest form of English?
Thanks :)
-
Shachi about 11 yearsgr8..thnks... bt will u plz elaborate 'Serialized Class'
-
Akshay Joy about 11 yearsWhen u Create WebService If you want to Return the Response as customer Class, You neeed to make Customer class Serializable. then only we can consume the same in client application
-
Sindri Þór over 8 yearsThats a nice answer and it should be marked as a correct answer. Straight to the point, i like it. @AkshayJoy
-
user3833732 over 8 years@AkshayJoy very aprreciative. I still need one clarification. With Reference to your above Ex.. Does this mean you have pre created a Class User(CustomerName, ProductNo) some where in your project, as you already know the return types of that WebService from the WSDL? Also, What if the response.getPropertyCount() returns 3, wont there be an array for userObj? And lastly, shouldnt start the index of response.getPropertyCount() with 0 instead of 1?