Reputation: 189594
I tested calling a soap 12 webservices with ksoap2. I used this code to call the webservice:
SoapObject request = new SoapObject(NAMESPACE, NAME);
request.addProperty("id", ID);
request.addProperty("name", "[email protected]");
request.addProperty("pw", "password");
request.addProperty("listid", 501);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.setOutputSoapObject(request);
AndroidHttpTransport client = new AndroidHttpTransport(URL);
try {
client.call(NAMESPACE + NAME, envelope);
Object response = envelope.getResponse();
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "IO Problem", e);
} catch (XmlPullParserException e) {
Log.e(getClass().getSimpleName(), "Parser Problem", e);
}
I now get the following exception:
org.xmlpull.v1.XmlPullParserException:expected: START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/soap/envelope/}soapenv:Envelope>@1:114 in java.io.InputStreamReader@44f28a80)
Is this a problem of the server response or is there something wrong in my code so far? It seems that other users have the same problem. If I change the Envelope to SoapEnvelope.VER11 I get a step further (I get an access denied response from the soap server probably because of a wrong URL) maybe there is additional info missing to create a VER12 envelope.
Upvotes: 2
Views: 9539
Reputation: 1
Try VR11
and replace your
Object response = envelope.getResponse();
with
SoapObject reponse=(SoapObject)envelope.getResponse();
Upvotes: 0
Reputation: 29912
Have you tried the various options for your envelope to see what the services expects?
E.g. you can set
envelope.dotNet = true;
envelope.headerOut = security; // this is an Element[] created before
envelope.encodingStyle = SoapEnvelope.ENC;
envelope.setAddAdornments(false);
envelope.implicitTypes = false;
and a bunch more. Check out the javadoc?
Also make sure to use the latest release of the ksoap2-android
project to get a bunch of fixes that are not in the normal sourceforge
project.
Upvotes: 4
Reputation: 1888
I use ksoap2 ver11 only... still it gives me an expected start_tag
error when I use it on another server other than localhost.
My webservices are hosted perfectly by my company's server but it gives this expected start tag error in Android 2.2 emulator and displays nothing (null error) in toast.
I am not sure but it can be the 'NetworkOnMainThread' exception in phone(Android 4.0).
Upvotes: 0
Reputation: 162
I had the same problem, I kept getting an exception “Permission Denied” from envelop.getResponse
.
I assumed something was wrong with my SOAP request and tried a number of changes to the envelop. Eventually after looking through some other boards I realized I needed an additional permission for android to allow this.
So add the following permission to your Android app's manifest.
<uses-permission android:name="android.permission.INTERNET">
Upvotes: -2
Reputation: 8458
What I did to make this work was use version 11, and it worked fine for me :-)
// Request model
SoapObject request = new SoapObject(namespace, Metodo);
// Envelop model
SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sobre.dotNet = true;
sobre.setOutputSoapObject(request);
// Transport model
HttpTransportSE transporte = new HttpTransportSE(url);
// Let's call it :)
transporte.call(accionSoap, sobre);
//Result
SoapPrimitive resultado = (SoapPrimitive) sobre.getResponse();
tv.setText("" + resultado.toString());
My variables:
private static final String accionSoap = "http://tempuri.org/ServicioAndroid";
private static final String Metodo = "ServicioAndroid";
private static final String namespace = "http://tempuri.org/";
private static final String url = "http://192.168.1.33/AutoEPOC_H/WS/WSAutoEPOC.asmx";
This Web Service was created usin dotNet. You can check your method, action, namespace and URL by running your Web Service using IIS.
If you understand Spanish, you can check these links:
http://www.youtube.com/watch?v=_MMByNiwqMc
http://programa-con-google.blogspot.com/2010/12/android-como-consumir-un-servicio-web.html
I hope this helps!
Upvotes: 1