Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SoapObject Result returns anyType{} as value when retuning a complexType object

I am calling a web service in my android app & the method is getGramaNiladhariData(), I am getting the result as a SoapObject.

result = (SoapObject) envelope.bodyIn;  Log.d("WS", String.valueOf(result));

And this is what I got for String.valueOf(result)

getGramaNiladhariDataResponse{getGramaNiladhariDataResult=anyType{gnName=anyType{}; address=anyType{}; workingDays=anyType{}; gnDivision=anyType{}; contactNumber=anyType{}; }; }

Here the method i am calling returns a complexType object,consist of 5 attributes. As i found in the internet i can't get a soap Object as the result of a webservice method which return a complexType object.If so,how should i get the values.

What I want to solve is why i am getting anyType{}, as the value ,instead of the real value. Any help would be appreciated

like image 298
erandi Avatar asked Sep 09 '12 06:09

erandi


1 Answers

Its too late to answer. but FYI and others who find this useful,

By Doing String.valueOf(result) you are printing the whole content of the body. but in order to get your values using parameters, first of all you need to hit in to correct SoapObject.

I don't know if there is any easy way to find correct SoapObject, but still this way do the trick, and once you get the correct SoapObject then you are done. find below how to find the correct SoapObject,

First you need to check the count of params in your very first SoapObject,

result.getPropertyCount();

you will get less amount of count for this since this is the very first cover,

then, Print and see which param gives you the corect details,

result.getProperty(0);
result.getProperty(1);
etc ...

Once you found the correct parameter, then grab that SoapObject. like this,

SoapObject result2 = (SoapObject) result.getProperty(0);

then check for the count of this object. and do the same as above until you get the correct SoapObject.

Once you found the last SoapObject it will print like this without useless strings,

anyType{gnName = Prasad; address = Address of the person; ; workingDays = 5; gnDivision = California; contactNumber = 0123456789}

Now you can go ahead with this object like this,

SoapObject result3 = (SoapObject) result2.getProperty(5);
Log.v("Name : ", result3.getProperty("gnName").toString());

And you will get the output in DDMS like below,

Name : Prasad

I guess this will help you, let me know if you have any further issues.

like image 88
Prasad De Zoysa Avatar answered Oct 19 '22 08:10

Prasad De Zoysa