views:

46435

answers:

12

I am having a lot of trouble finding good information on how to call a standard SOAP/WSDL web service with Android. All I've been able to find are either very convoluted documents and references to "kSoap2" and then some bit about parsing it all manually with SAX. ... Ok, that's fine but it's 2008 so I figured there should be some good library for calling standard web services.

The Web Service is just basically one created in NetBeans. I would like to have IDE support for generating the plumbing classes. I just need the easiest/most-elegant way to contact a WSDL based web service from an Android based phone. Thanks.

+1  A: 

I am sure you could make a little soap client with axis.

http://ws.apache.org/axis/java/install.html

mugafuga
+19  A: 

Android does not provide any sort of SOAP library. You can either write your own, or use something like kSOAP 2. As you note, others have been able to compile and use kSOAP2 in their own projects, but I haven't had to.

Google has shown, to date, little interest in adding a SOAP library to Android. My suspicion for this is that they'd rather support the current trends in Web Services toward REST-based services, and using JSON as a data encapsulation format. Or, using XMPP for messaging. But that is just conjecture.

XML-based web services are a slightly non-trivial task on Android at this time. Not knowing NetBeans, I can't speak to the tools available there, but I agree that a better library should be available. It is possible that the XmlPullParser will save you from using SAX, but I don't know much about that.

foxxtrot
Yeah, I think I will have to build a REST proxy. It seems pretty strange that Google has no interest in providing SOAP support. I tried the kSoap method, it's really not even a serious alternative. It is, at best, an ugly had that requires much scouring of newsgroups.
BobbyShaftoe
The reason is probably that SOAP is very verbose and doesn't serve the constraints of mobile computing well.
Neil D
This answer would be improved if someone could **suggest the best alternative** to calling web services with an Android App. Once people find this question and read it, that's what most of them will be looking for.
MGOwen
SOAP processing is also memory and processor intensive compared to a more concise format like JSON.
Jeremy Edwards
+10  A: 

org.apache.http.impl.client.DefaultHttpClient comes in the android sdk by default. That'll get you connected to the WSDL.

HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://www.example.com/" + URL);
response = httpClient.execute(httpGet, localContext);
Neil D
Yeah, this would be the route where I would have to manually parse everything, I wouldn't get an object oriented approach.
BobbyShaftoe
You mean you wouldn't get a free lunch. Manual parsing doesn't have anything to do with OO. I could parse everything on paper with my most advanced tool being an HB1 pencil and it would still be OO.
Neil D
+7  A: 

SOAP is an ill-suited technology for use on Android (or mobile devices in general) because of the processing/parsing overhead that's required. A REST services is a lighter weight solution and that's what I would suggest. Android comes with a SAX parser, and it's fairly trivial to use. If you are absolutely required to handle/parse SOAP on a mobile device then I feel sorry for you, the best advice I can offer is just not to use SOAP.

+9  A: 

It's true that due to it's overhead SOAP is not the best choice for data exchange with mobile devices. However, you might find yourself in situation in which you do not control the format of server output.

So, if you have to stick with SOAP, there is a kSOAP2 library patched for Android here:
http://code.google.com/p/ksoap2-android/

Viktor Bresan
+4  A: 

I had my tryst with KSOAP; I chose a rather simpler approach.

Given a WSDL file, create SOAP Request templates for each Request(for e.g.: using SOAP UI) and then substitute the values to be passed in code. POST this data to the service end point using DefaultHttpClient instance and get the response stream. Parse the Response Stream using an XML Pull parser.

Samuh
+2  A: 

If you can, go for JSON. Android comes with the complete org.json package

Yves
+4  A: 

Hi All, To call web service from mobile device(esp on Android phone),i have used a very simple way to done it. I have not used any web service client API in attempt to call web service.MY approach is as follows to make a call: 1)create a simple HttpConnection by using a java standard API HttpURLConnection. 2)Form a SOAP request.(You can take a help of SOAPUI to make a SOAP request) 3)Set doOutPut flag as true. 4)Set Http Header values like content-length,Content type,User-agent.Note do not forget to set Content-length. it is must. 5)Write entire SOAP request to OuputStream. 6)Call method to make connection and receive response(In my case i used getResonseCode). 7)If your received response code as 200.it means you are succeeded to call web service. 8) Now take an Input stream on same http connection and receive the string object.This String object is a SOAP response. 9) If Response code is other than 200 then take a ErrorInput stream on same HTTPobject and can receive the error if any. 10) Parse the received response using SAXParser(in my case) or DOMParaser or any other parsing mechanism.

I have implemented this procedure for android phone and it is successfully running.I am able to parse the response even if it is more than 700KB.

Rgds, Priyanjan

Priyanjan
+5  A: 

Hope this helps

http://www.vimeo.com/9633556

Thanks -Lino

Lino Tadros
It does! Thanks!
teedyay
+2  A: 

I hope this URL helps. http://www.anddev.org/calling_a_web_service_from_android-t348.html

Monte Chan
+1  A: 

You can have a look at WSClient++

Akash Kava
A: 

Hi,

I’ve created a new SOAP client for the Android platform, it is use a JAX-WS generated interfaces, but it is only a proof-of-concept yet.

If you are interested, please try the example and/or watch the source: http://wiki.javaforum.hu/display/ANDROIDSOAP/Home

:)

Gábor Auth