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.
To call a web service from a mobile device (especially on an Android phone), I have used a very simple way to do it. I have not used any web service client API in attempt to call the web service. My approach is as follows to make a call.
- Create a simple HTTP connection by using the Java standard API
HttpURLConnection
. - Form a SOAP request. (You can make help of SOAPUI to make a SOAP request.)
- Set doOutPut flag as true.
- Set HTTP header values like content-length, Content type, and User-agent. Do not forget to set Content-length value as it is a mandatory.
- Write entire the SOAP request to the output stream.
- Call the method to make a connection and receive the response (In my case I used
getResonseCode
). - If your received response code as
- It means you are succeeded to call web service.
- Now take an input stream on the same HTTP connection and receive the string object. This string object is a SOAP response.
- If the response code is other than 200 then take a
ErrorInput
stream on same HTTPobject and receive the error if any. - Parse the received response using SAXParser (in my case) or DOMParaser or any other parsing mechanism.
I have implemented this procedure for the Android phone, and it is successfully running. I am able to parse the response even if it is more than 700 KB.
0 comments:
Post a Comment