How to call a SOAP web service on Android
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.
Call a soap webservice in android
You can do any UI related operations in doInBackGround
, So move them in onPostExecute
methnod.
Because doInBackGround
is not a UI thread. Please read AsyncTask Document carefully. Whatever is the data you are returning from doInBackGround
, it is being taken as input to onPostExecute
.
So change your code as follows,
private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
}
@Override
protected String[] doInBackground(Void... params) {
Log.i(TAG, "doInBackground");
String[] data = sendRequest();
return data;
}
@Override
protected void onPostExecute(String[] result) {
Log.i(TAG, "onPostExecute");
if(result != null && result.length > 0){
textResult.setText( results[0]);
}
}
}
private String[] sendRequest(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//SoapObject
request.addProperty("@CountryName", "SPAIN");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
resultsRequestSOAP = envelope.getResponse();
String[] results = (String[]) resultsRequestSOAP;
}
catch (Exception aE)
{
aE.printStackTrace ();
}
}
Calling Soap webservice from android
I have a hunch that the emulator android version and the phone version are different.
But I have few suggestions. Use following:
httppost.setHeader("Accept-Charset","utf-8");
httppost.setHeader("Accept","text/xml,application/text+xml,application/soap+xml");
similarly, set content type as all of the above.
Implementing SOAP api in Android
SOAP is XML protocol for describing objects. While it works over many different protocols, using it over HTTP is basically XML over HTTP with a few extras settings required (usually HTTP Headers) to make it work.
WSDL is metadata that is used to describe the web services hosted on a given endpoint well enough that it is machine readable. Many client generation libraries for Web Services exist that can create a client that can call the web services.
If you can already call the web service endpoint and get a response using the apache client, then you can more or less ignore WSDL and all that stuff. You are doing enough SOAP to invoke the Web Service.
Once you get the response, deserialise / parse the XML using your favourite XML library.
Android has a couple built in, you can do it the old fashioned way with the DOM, use a library built on top of the DOM like dom4j or even the really old fashioned way with SAX.
For really big XML messages you want to use a streaming parser like Stax, but generally the DOM is easier to get going.
Finally write your own and make sure you add an answer to this SO Question :)
Android WSDL/SOAP service client
Android doesn't come with SOAP library. However, you can download 3rd party library here:
https://github.com/simpligility/ksoap2-android
If you need help using it, you might find this thread helpful:
How to call a .NET Webservice from Android using KSOAP2?
Related Topics
Java Equivalent to PHP'S Preg_Replace_Callback
Why Does My Function That Calls an API or Launches a Coroutine Return an Empty or Null Value
How to Add a Timestamp in Firestore With Android
Base 64 Encode and Decode Example Code
Do Line Endings Differ Between Windows and Linux
What Does "Could Not Find or Load Main Class" Mean
Difference Between Chromedriver and Webdriver in Selenium
How to Avoid Arrayindexoutofboundsexception or Indexoutofboundsexception
How to Use the Tostring Method in Java
How to Get a File'S Media Type (Mime Type)
Signing Pdfs on a Server Document Using a Signature from the User
How to Return a Documentsnapshot as a Result of a Method
How to Redirect Multiple Types of Users to Their Respective Activities
How to Change the Decimal Separator of Decimalformat from Comma to Dot/Point
Javafx on Linux Is Showing a "Graphics Device Initialization Failed For: Es2, Sw"
Connect Java to a MySQL Database