Returning Array of Primitive Types with KSOAP



KSOAP until recently had an issue with returning an array of primitive types. With the new patch the issue is solved. If you haven't downloaded the newest version of
KSOAP available on GitHub, you can use the following snippet:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            SoapSerializationEnvelope envelope =
            new SoapSerializationEnvelope(SoapEnvelope.VER11);
            //envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);

                KvmSerializable ks = (KvmSerializable)envelope.bodyIn;
                for(int i=0;i<ks.getPropertyCount();i++)
                {
                   ks.getProperty(i); //if complex type is present then you can cast this to SoapObject and if primitive type is returned you can use toString() to get actuall value.
                }



This code was written by nebe.daredevil

If anyone else is having trouble to return array of primitive types with KSOAP, might consider the issue thread on Google Code

I hope the agony with KSOAP is near an end with this.

28 comments:

Valter said...

Your blog is helping me a lot. Took me out of a hole.

Tanks

SeeSharpWriter said...

I am so glad I helped someone.

Anonymous said...

Thanks great blog you have help me lots, only one thing how to feed ks.getProperty(i); right into the SQLite on the device?

SeeSharpWriter said...

Perhaps you should write some code to insert the retrieved property into the SQLite database. I believe you should refer to some tutorial on working with SQLite and then combine the codes.

Unknown said...

Hello,
i am trying to call a web service (SOAP - .asmx web service [.net]) since last 2 to 3 days. I get the response but my problem is the response is neither JSON nor XML, so i didn't understand how can i parse my response string?

here i am putting my response string
----------------------------------------------
anyType{NewDataSet=anyType{


Table=anyType{AdSpaceID=423; AdspaceName=Hoarding at football, (Amul); Address=football,(Amul)-Ahmedabad; };

Table=anyType{AdSpaceID=424; AdspaceName=Hoarding at football, tow. Bhulabhai.(Amul); Address=football, tow. Bhulabhai.(Amul)-Ahmedabad; };

Table=anyType{AdSpaceID=425; AdspaceName=Hoarding at Bhulabhai 4 Road Junction; Address=Bhulabhai 4 Road Junction-Ahmedabad; };

Table=anyType{AdSpaceID=426; AdspaceName=Hoarding at Bhulabhai Park, Tow. S.T. Stand; Address=Bhulabhai Park, Tow. S.T. Stand-Ahmedabad; }; }; }
----------------------------------------------

above string is my response string and i want to
convert it into xml, so i can parse it...

Help me

Than you

Anonymous said...

hi seesharpwriter,
i followed your tutorial and it helped me a lot. thanks for that.
i am having an issue, i cannot access the array returned from my web service in android, i can access an individual data but not the array.
I am getting xmlpullparserexception expected Start tag error.

public class MainActivity extends Activity {

private final String NAMESPACE = "urn:hellowsdl";
private final String URL = "http://10.0.2.2/WebServiceServer/test.php?wsdl"; // WSDL URL
private final String SOAP_ACTION = "urn:hellowsdl#hello";
private final String METHOD_NAME = "hello"; // Method on web service

@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}

Button btnSend = (Button) this.findViewById(R.id.btnSend);
btnSend.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/*menu M=new menu();

PropertyInfo pi = new PropertyInfo();
M.Menu_id=1;
pi.setName("M");
pi.setValue(M);
pi.setType(M.getClass());*/


TextView txtResult = (TextView) findViewById(R.id.txtResult);

EditText txtName = (EditText) findViewById(R.id.txtName);


SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//request.addProperty(pi);
request.addProperty("strName", txtName.getText().toString());

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);

envelope.setOutputSoapObject(request);
//envelope.addMapping(NAMESPACE, "menu",new menu().getClass());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//androidHttpTransport.debug=true;


try {

androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.getResponse();
System.out.println(result);
if (result != null) {

KvmSerializable ks = (menu)(KvmSerializable)envelope.bodyIn;
for(int i=0;i<ks.getPropertyCount();i++)
{
txtResult.setText(ks.getProperty(i).toString());


}} else {
Toast.makeText(getApplicationContext(),
"Web Service not Response!", Toast.LENGTH_LONG)
.show();


}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}


could you please help me with that?
thanks ;)


Anonymous said...

I need to send some value data(i receive this data from one activity) to a webservice and receive 10elements, but the .call have an exeption

manimaran said...

Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care
http://traininginmedavakkam.in/training-courses/msazure-training-in-medavakkam/
http://traininginmedavakkam.in/training-courses/sap-bo-training-in-medavakkam/
http://traininginmedavakkam.in/training-courses/qlikview-training-in-medavakkam/
http://traininginmedavakkam.in/training-courses/tableau-training-in-medavakkam/
http://traininginmedavakkam.in/training-courses/datastage-training-in-medavakkam/
http://traininginmedavakkam.in/training-courses/machine-learning-training-in-medavakkam/
http://traininginmedavakkam.in/training-courses/data-science-training-in-medavakkam/
http://traininginmedavakkam.in/training-courses/oracle-dba-training-in-medavakkam/
http://traininginmedavakkam.in/training-courses/sql-server-dba-training-in-medavakkam/

sanjay said...

We are an online store for mens and womens fashionable item accessories in india online.ڈپلیکیٹ برانڈڈ گھڑیاں آن لائن

Zayn said...

https://juiceapp.in/blog/benefits-of-cold-pressed-juices/

zayn said...

Amazing Post

Outdoor Hoarding in Hyderabad said...

Thanks for another wonderful post. Where else may anybody get that type of information in such an ideal way of writing? I’ve a presentation next week, and I’m on the look for such info.

Quickbooks Expert said...

Nice & Informative Blog !
If you are looking for the best accounting software that can help you manage your business operations. call us at QuickBooks Customer Service Number 1-855-974-6537.

Waheed said...

Thnks for this post. keep it up. 먹튀검증

AnnaSereno said...

Hey! Mind-blowing blog. Keep writing such beautiful blogs. In case you are struggling with issues on QuickBooks software, dial QuickBooks unrecoverable error (855)756-1077. The team, on the other end, will assist you with the best technical services.

Musheer said...

Thanks for sharing this blog

Zayn said...

Amazing Article, thanks for sharing

janvi said...

Thankyou for sharing

QuickBooks Support said...

Nice Blog !
At times, while filing form 941, you may face QuickBooks Form 941 Error when the total sum of the tax amount exceeds $2500. To fix such issue, you must contact our experts via QuickBooks Support Number and get permanent ways to solve QuickBooks problems.

johnson said...

buy marijuana-flowers online
buy marijuana-edibles online
buy cbd-oils online
buy vapes-and-carts online
buy accessories online
buy auto-flowering-seeds online
buy granddaddy-purple online
buy psychedelics online
buy cannabis-concentrates-online
buy og-kush online
buy dmt-nn-dimethyltryptamine online
buy blue-cheese-weed online
buy purple-haze online
buy strawberry-cough online
buy black-diamond-kush online
buy blue-dream online
buy moon-rock online

Lauren Kathy said...

Hey! Mind-blowing blog. Keep writing such beautiful blogs. In case you are struggling with issues on QuickBooks software, dial QuickBooks Customer Service Phone Number . The team, on the other end, will assist you with the best technical services.

Unknown said...

This site seems to inspire me a lot. Thank you so much for organizing and providing this quality information in an easy to understand way. I think that a healthy era of big data can be maintained only when such high-quality information is continuously produced. And I, too, are working hard to organize and provide such high-quality information. It would be nice to come in once and get information.

Also visit my site:토토사이트


oworldsmeyang said...

I don’t know if it’s just me or if perhaps everyone
else encountering issues with your website. It appears like some of the written text on your posts
are running off the screen. Can someone else please provide
feedback and let me know if this is happening to them too?
This could be a issue with my web browser because I’ve had this happen before.오피월드


2YOUNGYANG
Cheers

HR Consultancy Firms said...

Hi! I really like your content your post is really informative.

lms online



learning management

메이저사이트추천 said...

When did you start writing articles related to ? To write a post by reinterpreting the 메이저사이트추천 I used to know is amazing. I want to talk more closely about , can you give me a message?
xfdh

raju said...

wordpress website design agency in united states Need professional WordPress Web Design Services? We're experts in developing attractive mobile-friendly WordPress websites for businesses. Contact us today!

Farah Noor said...

In this game, more than a hundred players parachute onto an island and scavenge for weapons and equipment to kill others when avoiding getting killed themselves .Pubg License Key 2022

seoservicesinusa said...
This comment has been removed by the author.

Post a Comment